Module: Jiralicious::Parsers::FieldParser

Included in:
Base
Defined in:
lib/jiralicious/parsers/field_parser.rb

Overview

The FieldParser module is an extention that assists in managing hash parsing and implementation.

Instance Method Summary collapse

Instance Method Details

#parse!(fields) ⇒ Object

Parses an Array or Hash into the current class object.

Arguments

:fields (required) fields to be parsed



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jiralicious/parsers/field_parser.rb', line 18

def parse!(fields)
  unless fields.is_a?(Hash)
    raise ArgumentError
  end
  @jiralicious_field_parser_data = {}
  singleton = class << self; self end

  fields.each do |field, details|
    if details.is_a?(Hash)
      next if details["name"].nil?
      method_value = mashify(details["value"])
      method_name  = normalize(details["name"])
    else
      method_value = mashify(details)
      method_name = normalize(field)
    end

    if singleton.method_defined?(method_name)
      method_name = "jira_#{method_name}"
    end

    @jiralicious_field_parser_data[method_name] = method_value
    singleton.send :define_method, method_name do
      @jiralicious_field_parser_data[method_name]
    end
  end
end