lib/jiralicious/parsers/field_parser.rb in jiralicious-0.0.6 vs lib/jiralicious/parsers/field_parser.rb in jiralicious-0.1.0

- old
+ new

@@ -8,15 +8,18 @@ end @jiralicious_field_parser_data = {} singleton = class << self; self end fields.each do |field, details| - next if details["name"].nil? - method_value = mashify(details["value"]) - method_name = details["name"].gsub(/(\w+)([A-Z].*)/, '\1_\2'). - gsub(/\W/, "_"). - downcase + 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 @@ -26,9 +29,15 @@ end end end private + + def normalize(name) + name.gsub(/(\w+)([A-Z].*)/, '\1_\2'). + gsub(/\W/, "_"). + downcase + end def mashify(data) if data.is_a?(Array) data.map { |d| mashify(d) } elsif data.is_a?(Hash)