Class: NPR::Entity::Image
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hasBorder ⇒ Object
Returns the value of attribute hasBorder.
-
#id ⇒ Object
Returns the value of attribute id.
-
#link ⇒ Object
Returns the value of attribute link.
-
#src ⇒ Object
Returns the value of attribute src.
-
#type ⇒ Object
Returns the value of attribute type.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#crop(type) ⇒ Object
Find a crop by its type.
-
#initialize(json) ⇒ Image
constructor
NOTE that the “link” attribute here is not cast into a Link object, and the “url” parameter is ignored.
-
#primary? ⇒ Boolean
Determine if this image is the primary image (as defined by NPR).
-
#standard? ⇒ Boolean
Determine if this image is the standard image (as defined by NPR).
Methods included from Concern::ShallowAttributes
Methods included from Concern::Relation
Constructor Details
#initialize(json) ⇒ Image
NOTE that the “link” attribute here is not cast into a Link object, and the “url” parameter is ignored. Instead, just calling image.link
will return the URL parameter.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/npr/entity/image.rb', line 17 def initialize(json) @id = json["id"].to_i @type = json["type"] @width = json["width"].to_i @src = json["src"] @hasBorder = json["hasBorder"] == "true" if json["link"] @link = json["link"]["url"] end extract_shallow_attributes(json) create_relations(json) end |
Instance Attribute Details
#hasBorder ⇒ Object
Returns the value of attribute hasBorder.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def hasBorder @hasBorder end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def link @link end |
#src ⇒ Object
Returns the value of attribute src.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def src @src end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def type @type end |
#width ⇒ Object
Returns the value of attribute width.
7 8 9 |
# File 'lib/npr/entity/image.rb', line 7 def width @width end |
Instance Method Details
#crop(type) ⇒ Object
Find a crop by its type.
Arguments:
-
(String) type - the type of crop you’re looking for
Examples:
image.crop("enlargement") #=> NPR::Entity::Crop
image.crop("missing") #=> nil
Returns: An NPR::Entity::Crop, or nil if none found.
46 47 48 |
# File 'lib/npr/entity/image.rb', line 46 def crop(type) self.crops.find { |c| c.type == type } end |
#primary? ⇒ Boolean
Determine if this image is the primary image (as defined by NPR).
Returns: Boolean
54 55 56 |
# File 'lib/npr/entity/image.rb', line 54 def primary? @type == "primary" end |
#standard? ⇒ Boolean
Determine if this image is the standard image (as defined by NPR).
Returns: Boolean
62 63 64 |
# File 'lib/npr/entity/image.rb', line 62 def standard? @type == "standard" end |