Class: NPR::Entity::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/npr/entity/image.rb

Direct Known Subclasses

PromoArt

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concern::ShallowAttributes

included

Methods included from Concern::Relation

included

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

#hasBorderObject

Returns the value of attribute hasBorder.



7
8
9
# File 'lib/npr/entity/image.rb', line 7

def hasBorder
  @hasBorder
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/npr/entity/image.rb', line 7

def id
  @id
end

Returns the value of attribute link.



7
8
9
# File 'lib/npr/entity/image.rb', line 7

def link
  @link
end

#srcObject

Returns the value of attribute src.



7
8
9
# File 'lib/npr/entity/image.rb', line 7

def src
  @src
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/npr/entity/image.rb', line 7

def type
  @type
end

#widthObject

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

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/npr/entity/image.rb', line 62

def standard?
  @type == "standard"
end