Codebase list golang-github-ungerik-go-sysfs / eaa365d7-4f4a-4f9d-a332-4c85c477ecfd/main object.go
eaa365d7-4f4a-4f9d-a332-4c85c477ecfd/main

Tree @eaa365d7-4f4a-4f9d-a332-4c85c477ecfd/main (Download .tar.gz)

object.go @eaa365d7-4f4a-4f9d-a332-4c85c477ecfd/mainraw · history · blame

package sysfs

import (
	// "os"
	"strings"
)

type Object string

func (obj Object) Exists() bool {
	return dirExists(string(obj))
}

func (obj Object) Name() string {
	return string(obj)[strings.LastIndex(string(obj), "/")+1:]
}

func (obj Object) SubObjects() []Object {
	path := string(obj) + "/"
	objects := make([]Object, 0)
	lsDirs(path, func(name string) {
		objects = append(objects, Object(path+name))
	})
	return objects
}

func (obj Object) SubObject(name string) Object {
	return Object(string(obj) + "/" + name)
}

func (obj Object) Attributes() []Attribute {
	path := string(obj) + "/"
	attribs := make([]Attribute, 0)
	lsFiles(path, func(name string) {
		attribs = append(attribs, Attribute{Path: path + name})
	})
	return attribs
}

func (obj Object) Attribute(name string) *Attribute {
	return &Attribute{Path: string(obj) + "/" + name}
}