Class: HornOfPlenty::Adapters::Github::Parsers::Card

Inherits:
Object
  • Object
show all
Includes:
Parsers::Hash
Defined in:
lib/horn_of_plenty/adapters/github/parsers/card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#rawObject

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_idObject



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_typeObject



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_atObject



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

#descriptionObject



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

#idObject



21
22
23
# File 'lib/horn_of_plenty/adapters/github/parsers/card.rb', line 21

def id
  @id                                    ||= parse_text(raw, 'id')
end

#lane_idObject



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

#repositoryObject



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

#titleObject



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_atObject



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