Class: SimpleAMS::Document::Fields

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/simple_ams/document/fields.rb

Defined Under Namespace

Classes: Field

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Fields

Returns a new instance of Fields.



8
9
10
11
# File 'lib/simple_ams/document/fields.rb', line 8

def initialize(options)
  @options = options
  @members = options.fields # [:field1, :field2]
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
16
17
18
# File 'lib/simple_ams/document/fields.rb', line 13

def [](key)
  found = members.find { |field| field == key }
  return nil unless found

  value_of(found)
end

#any?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simple_ams/document/fields.rb', line 31

def any?
  members.any?
end

#eachObject

TODO: Can we make this faster?



21
22
23
24
25
26
27
28
29
# File 'lib/simple_ams/document/fields.rb', line 21

def each
  return enum_for(:each) unless block_given?

  members.each do |key|
    yield value_of(key)
  end

  self
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/simple_ams/document/fields.rb', line 35

def empty?
  members.empty?
end