Class: Gillbus::Parser
- Inherits:
-
Object
- Object
- Gillbus::Parser
- Defined in:
- lib/gillbus/helpers/parser.rb
Constant Summary collapse
- NULL_CONST =
'null'.freeze
- TRUE_CONST =
'true'.freeze
- YES_CONST =
'Y'.freeze
- DATE_FORMAT_CONST =
'%d.%m.%Y'.freeze
- TIME_FORMAT_REGEXP =
/^ ( \d\d:\d\d ) (?: :\d\d )? $/x.freeze
- DEFAULT_TIMEZONE =
'Europe/Kiev'.freeze
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(instance:, doc:, fields:, parent:, options: {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(instance:, doc:, fields:, parent:, options: {}) ⇒ Parser
Returns a new instance of Parser.
18 19 20 21 22 23 24 |
# File 'lib/gillbus/helpers/parser.rb', line 18 def initialize(instance:, doc:, fields:, parent:, options: {}) @instance = instance @doc = doc @fields = fields @parent = parent @options = end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
13 14 15 |
# File 'lib/gillbus/helpers/parser.rb', line 13 def doc @doc end |
#fields ⇒ Object
Returns the value of attribute fields.
15 16 17 |
# File 'lib/gillbus/helpers/parser.rb', line 15 def fields @fields end |
#instance ⇒ Object
Returns the value of attribute instance.
14 15 16 |
# File 'lib/gillbus/helpers/parser.rb', line 14 def instance @instance end |
#parent ⇒ Object
Returns the value of attribute parent.
16 17 18 |
# File 'lib/gillbus/helpers/parser.rb', line 16 def parent @parent end |
Instance Method Details
#parse ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gillbus/helpers/parser.rb', line 26 def parse fields.each do |name:, key:, type:, root:| value = if type == :datetime_combined datetime_combined(key) else raw_value = fetch_value(key: key, root: root) make_one_or_many(type, raw_value) end instance.send "#{name}=", value unless value.nil? end instance end |