Class: KCNA::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/kcna/article.rb

Overview

Represents an article.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, **attrs) ⇒ Article

Returns a new instance of Article.

Parameters:

  • attrs (Hash)

    attributes of article

Options Hash (**attrs):

  • :date (Date)

    date of the article

  • :content (String)

    content of the article

  • :main_title (String)

    main title of the article

  • :sub_title (String)

    subtitle of the article

  • :display_title (String)
  • :movie_count (Integer)

    the number of movies related to the article

  • :photo_count (Integer)

    the number of photos related to the article

  • :music_count (Integer)

    the number of musics related to the article



48
49
50
51
52
# File 'lib/kcna/article.rb', line 48

def initialize(id, **attrs)
  raise "id is not a string" unless id.kind_of?(String)
  @id = id
  @attrs = attrs
end

Instance Attribute Details

#contentString (readonly)

Returns content of the article.

Returns:

  • (String)

    content of the article



19
# File 'lib/kcna/article.rb', line 19

attr_reader_hash :content

#dateDate (readonly)

Returns date of the article.

Returns:

  • (Date)

    date of the article



16
# File 'lib/kcna/article.rb', line 16

attr_reader_hash :date

#display_titleString (readonly)

Returns:

  • (String)


28
# File 'lib/kcna/article.rb', line 28

attr_reader_hash :display_title

#idString (readonly)

Returns ID of the article.

Returns:

  • (String)

    ID of the article



4
5
6
# File 'lib/kcna/article.rb', line 4

def id
  @id
end

#main_titleString (readonly)

Returns main title of the article.

Returns:

  • (String)

    main title of the article



22
# File 'lib/kcna/article.rb', line 22

attr_reader_hash :main_title

#movie_countInteger (readonly)

Returns the number of movies related to the article.

Returns:

  • (Integer)

    the number of movies related to the article



31
# File 'lib/kcna/article.rb', line 31

attr_reader_hash :movie_count, 0

#music_countInteger (readonly)

Returns the number of musics related to the article.

Returns:

  • (Integer)

    the number of musics related to the article



37
# File 'lib/kcna/article.rb', line 37

attr_reader_hash :music_count, 0

#photo_countInteger (readonly)

Returns the number of photos related to the article.

Returns:

  • (Integer)

    the number of photos related to the article



34
# File 'lib/kcna/article.rb', line 34

attr_reader_hash :photo_count, 0

#sub_titleString (readonly)

Returns subtitle of the article.

Returns:

  • (String)

    subtitle of the article



25
# File 'lib/kcna/article.rb', line 25

attr_reader_hash :sub_title

Instance Method Details

#to_hHash

Convert the article to a hash table.

Returns:

  • (Hash)


56
57
58
# File 'lib/kcna/article.rb', line 56

def to_h
  self.class.instance_variable_get(:@attribute_keys).map { |k| [k, self.send(k)] }.to_h
end