Class: NPR::Entity::Story
- Includes:
- Concern::LinksAssociation
- Defined in:
- lib/npr/entity/story.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
————————-.
-
#id ⇒ Object
————————-.
-
#text ⇒ Object
————————-.
-
#textWithHtml ⇒ Object
————————-.
-
#thumbnail ⇒ Object
————————-.
Class Method Summary collapse
-
.find(id) ⇒ Object
————————- Find a story based on ID.
-
.find_by_id(id) ⇒ Object
————————- Same as above, but returns
nilif a single story isn’t returned.
Instance Method Summary collapse
-
#initialize(json) ⇒ Story
constructor
————————-.
-
#primary_image ⇒ Object
————————- The primary image.
Methods included from Concern::LinksAssociation
Methods included from Concern::ShallowAttributes
Methods included from Concern::Relation
Constructor Details
#initialize(json) ⇒ Story
124 125 126 127 128 129 130 131 |
# File 'lib/npr/entity/story.rb', line 124 def initialize(json) @_json = json @id = @_json["id"].to_i build_text extract_shallow_attributes(@_json) create_relations(@_json) end |
Instance Attribute Details
#container ⇒ Object
83 84 85 |
# File 'lib/npr/entity/story.rb', line 83 def container @container end |
#id ⇒ Object
83 84 85 |
# File 'lib/npr/entity/story.rb', line 83 def id @id end |
#text ⇒ Object
83 84 85 |
# File 'lib/npr/entity/story.rb', line 83 def text @text end |
#textWithHtml ⇒ Object
83 84 85 |
# File 'lib/npr/entity/story.rb', line 83 def textWithHtml @textWithHtml end |
#thumbnail ⇒ Object
83 84 85 |
# File 'lib/npr/entity/story.rb', line 83 def thumbnail @thumbnail end |
Class Method Details
.find(id) ⇒ Object
Find a story based on ID
This method is meant to be a quick, easy way to find a story just by its ID.
If you need more control over what gets fetched and how, use NPR::Client directly, or the other chainable methods (where, order, etc.)
It is not possible to pass options into this method. Therefore, you must globally configure at least the apiKey using NPR.configure.
Example:
NPR::Entity::Story.find(1000)
28 29 30 31 32 33 34 35 36 |
# File 'lib/npr/entity/story.rb', line 28 def find(id) response = query_by_id(id) if !response..empty? response. else response.list.stories.first end end |
.find_by_id(id) ⇒ Object
Same as above, but returns nil if a single story isn’t returned.
41 42 43 44 45 46 47 48 49 |
# File 'lib/npr/entity/story.rb', line 41 def find_by_id(id) response = query_by_id(id) if !response..empty? nil else response.list.stories.first end end |
Instance Method Details
#primary_image ⇒ Object
The primary image.
Looks at the “type” attribute on an image and finds any with type “primary”. If none are found, then return the first image of any type.
140 141 142 143 144 145 |
# File 'lib/npr/entity/story.rb', line 140 def primary_image @primary_image ||= begin primary = self.images.find(&:primary?) primary || self.images.first end end |