Class: Wikirate4ruby::Entities::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/wikirate4ruby/entities/card.rb

Constant Summary collapse

CARD_ATTRIBUTES =
%i[id type name content url codename html_url created_at updated_at requested_at].freeze

Instance Method Summary collapse

Constructor Details

#initialize(card) ⇒ Card

Returns a new instance of Card.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wikirate4ruby/entities/card.rb', line 7

def initialize(card)
  @data = card
  @id = get_content 'id'
  @type = @data['type'].is_a?(String) ? @data['type'] : @data['type']['name']
  @name = @data['name']
  @content = @data['content']
  @url = @data['url']
  @codename = @data['codename']
  @html_url = @data['html_url']
  @created_at = @data['created_at']
  @updated_at = @data['updated_at']
  @requested_at = @data['requested_at']
end

Instance Method Details

#as_jsonHash{String->Unknown

Returns ].

Returns:

  • (Hash{String->Unknown)

    ]



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wikirate4ruby/entities/card.rb', line 26

def as_json
  {
    'id' => @id,
    'type' => @type,
    'name' => @name,
    'content' => @content,
    'url' => @url,
    'codename' => @codename,
    'html_url' => @html_url,
    'created_at' => @created_at,
    'updated_at' => @updated_at,
    'requested_at' => @requested_at
  }
end

#raw_jsonObject



21
22
23
# File 'lib/wikirate4ruby/entities/card.rb', line 21

def raw_json
  JSON.pretty_generate(@data)
end

#to_json(*_args) ⇒ Object



41
42
43
# File 'lib/wikirate4ruby/entities/card.rb', line 41

def to_json(*_args)
  JSON.pretty_generate(to_hash)
end

#to_sObject



45
46
47
# File 'lib/wikirate4ruby/entities/card.rb', line 45

def to_s
  to_json
end