Class: YouTrack::Parser::IssueParser

Inherits:
Base
  • Object
show all
Defined in:
lib/you_track/parser/issue_parser.rb

Direct Known Subclasses

IssuesParser

Instance Attribute Summary

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

#initialize, #parse_fields

Constructor Details

This class inherits a constructor from YouTrack::Parser::Base

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/you_track/parser/issue_parser.rb', line 18

def parse
  results = raw["issue"].dup

  fields = results.delete("field")
  standard_fields = fields.select { |k| k["xsi:type"] == "SingleField" }
  fields = fields - standard_fields
  attachments = fields.select { |k| k["xsi:type"] == "AttachmentField" }
  custom_fields = fields - attachments

  results.merge!(parse_fields(standard_fields))

  user_fields = custom_fields.select { |k| k["xsi:type"] == "MultiUserField" }

  custom_fields -= user_fields

  results["custom_fields"] = parse_fields(custom_fields).merge(parse_user_fields(user_fields))
  results["attachments"]   = parse_attachments(attachments)
  results["comments"]      = results.delete("comment")

  results
end

#parse_attachments(attachments) ⇒ Object



2
3
4
5
6
7
# File 'lib/you_track/parser/issue_parser.rb', line 2

def parse_attachments(attachments)
  attachments.inject([]) { |r, a|
    value = a["value"]
    r << {"id" => value["id"], "url" => value["url"], "content" => value["__content__"]}
  }
end

#parse_user_fields(user_fields) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/you_track/parser/issue_parser.rb', line 9

def parse_user_fields(user_fields)
  user_fields.inject({}) { |r, a|
    outer_value = a["value"]
    value = outer_value.delete("__content__")

    r.merge(a["name"] => {"value" => value}.merge(outer_value))
  }
end