Class: SSO::Elements::Config
- Inherits:
-
Object
- Object
- SSO::Elements::Config
- Defined in:
- lib/sso/elements/config.rb
Constant Summary collapse
- CFG_AVAIL =
{ 150 => 'PW_1.0.2_v150.cfg', 152 => 'PW_1.0.2_v152.cfg' }
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#type ⇒ Object
Returns the value of attribute type.
-
#types ⇒ Object
Returns the value of attribute types.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #add_element(element) ⇒ Object
- #elements ⇒ Object
- #elements_loaded? ⇒ Boolean
- #find_element_by_id(id) ⇒ Object
- #find_element_by_name(name) ⇒ Object
- #find_elements_by_name(name) ⇒ Object
- #grouped_field_quantity ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
19 20 21 22 23 24 |
# File 'lib/sso/elements/config.rb', line 19 def initialize @offsets = [] @fields = [] @types = [] @values = [] end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def fields @fields end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def name @name end |
#offset ⇒ Object
Returns the value of attribute offset.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def offset @offset end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def type @type end |
#types ⇒ Object
Returns the value of attribute types.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def types @types end |
#values ⇒ Object
Returns the value of attribute values.
7 8 9 |
# File 'lib/sso/elements/config.rb', line 7 def values @values end |
Instance Method Details
#add_element(element) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/sso/elements/config.rb', line 53 def add_element(element) @values << element.to_value @elements << element true end |
#elements ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/sso/elements/config.rb', line 41 def elements return @elements if @elements @elements = values.map do |value| Element.from_value(self, value) end end |
#elements_loaded? ⇒ Boolean
49 50 51 |
# File 'lib/sso/elements/config.rb', line 49 def elements_loaded? !@elements.nil? end |
#find_element_by_id(id) ⇒ Object
60 61 62 63 64 |
# File 'lib/sso/elements/config.rb', line 60 def find_element_by_id(id) elements.find do |element| element.id == id end end |
#find_element_by_name(name) ⇒ Object
66 67 68 69 70 |
# File 'lib/sso/elements/config.rb', line 66 def find_element_by_name(name) elements.find do |element| element.name.to_s.downcase == name.to_s.downcase end end |
#find_elements_by_name(name) ⇒ Object
72 73 74 75 76 |
# File 'lib/sso/elements/config.rb', line 72 def find_elements_by_name(name) elements.select do |element| element.name.to_s.downcase.include?(name.to_s.downcase) end end |
#grouped_field_quantity ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sso/elements/config.rb', line 77 def grouped_field_quantity return @fields_quantity if @fields_quantity @fields_quantity = {} fields.each do |field| @fields_quantity[field] ||= 0 @fields_quantity[field] += 1 end @fields_quantity end |
#to_json ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sso/elements/config.rb', line 26 def to_json values.map do |value| result = {} value.each_with_index do |data, index| result[fields[index]] = { 'data' => data, 'type' => types[index] } end result end end |