Class: RubDev::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubdev/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ List

Returns a new instance of List.



26
27
28
29
# File 'lib/rubdev/list.rb', line 26

def initialize (list)
  @top = list
  rewind
end

Instance Method Details

#[](name) ⇒ Object



54
55
56
# File 'lib/rubdev/list.rb', line 54

def [] (name)
  by_name(name).value
end

#by_name(name) ⇒ Object



41
42
43
44
# File 'lib/rubdev/list.rb', line 41

def by_name (name)
  RubDev::C.udev_list_entry_get_by_name(@pointer, name)
  self
end

#each(&blk) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubdev/list.rb', line 58

def each(&blk)
  array = []
  pointer = @pointer
  rewind
  unless @pointer.null?
    blk.call(name, value) if blk
    array << [name, value]
    self.next
  end
  @pointer = pointer
  blk ? array : Enumerator.new(array)
end

#nameObject



46
47
48
# File 'lib/rubdev/list.rb', line 46

def name
  RubDev::C.udev_list_entry_get_name(@pointer)
end

#nextObject



36
37
38
39
# File 'lib/rubdev/list.rb', line 36

def next
  @pointer = RubDev::C.udev_list_entry_get_next(@pointer)
  self
end

#rewindObject



31
32
33
34
# File 'lib/rubdev/list.rb', line 31

def rewind
  @pointer = @top
  self
end

#valueObject



50
51
52
# File 'lib/rubdev/list.rb', line 50

def value
  RubDev::C.udev_list_entry_get_value(@pointer)
end