Class: HornOfPlenty::Adapters::Github::Parsers::Card
- Inherits:
-
Object
- Object
- HornOfPlenty::Adapters::Github::Parsers::Card
- Includes:
- Parsers::Hash
- Defined in:
- lib/horn_of_plenty/adapters/github/parsers/card.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Class Method Summary collapse
Instance Method Summary collapse
- #content_id ⇒ Object
- #content_type ⇒ Object
- #created_at ⇒ Object
- #description ⇒ Object
- #id ⇒ Object
-
#initialize(raw:) ⇒ Card
constructor
A new instance of Card.
- #lane_id ⇒ Object
- #repository ⇒ Object
- #title ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(raw:) ⇒ Card
17 18 19 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 17 def initialize(raw:) self.raw = raw end |
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
15 16 17 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 15 def raw @raw end |
Class Method Details
.to_model(raw_item) ⇒ Object
81 82 83 84 85 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 81 def self.to_model(raw_item) return NullObjects::Card.instance unless raw_item Models::Card.from_parser(parser: new(raw: raw_item)) end |
Instance Method Details
#content_id ⇒ Object
53 54 55 56 57 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 53 def content_id @content_id ||= parse_text(raw, 'content_url') do |url| url.match(%r{\A.*/(\d+)\z})[1] end end |
#content_type ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 39 def content_type @content_type ||= parse_text(raw, 'content_url', yield_if_nil: true) do |url| if url CoreExt::String.singularize( CoreExt::String.camelize(url.match(%r{\A.*/(.*?)/\d+\z})[1]), ) else 'Note' end end end |
#created_at ⇒ Object
73 74 75 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 73 def created_at @created_at ||= parse_time(raw, 'created_at') end |
#description ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 65 def description @description ||= parse_text(raw, 'note') do |note| match = note.delete("\r").match(/\A.*?(?:\n)+(.*)/m) match[1] if match end end |
#id ⇒ Object
21 22 23 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 21 def id @id ||= parse_text(raw, 'id') end |
#lane_id ⇒ Object
25 26 27 28 29 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 25 def lane_id @lane_id ||= parse_text(raw, 'column_url') do |url| url.match(%r{\A.*/(\d+)\z})[1] end end |
#repository ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 31 def repository @repository ||= parse_text(raw, 'column_url') do |url| repo_name = url.match(%r{\A.*/repos/((?:[^/]+/){2}).*\z})[1] repo_name && repo_name[0..-2] end end |
#title ⇒ Object
59 60 61 62 63 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 59 def title @title ||= parse_text(raw, 'note') do |note| note.delete("\r").match(/\A(.*)$/)[1] end end |
#updated_at ⇒ Object
77 78 79 |
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 77 def updated_at @updated_at ||= parse_time(raw, 'updated_at') end |