Class: Rb::Lomo::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-lomo/photo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Photo

Expects a JSON object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rb-lomo/photo.rb', line 37

def initialize json
  @json       = json
  @id         = @json['id']
  @title      = @json['title']
  @description= @json['description']
  @url        = @json['url']
  @user       = User.new @json['user']

  if @json['camera']
    @camera     = Camera.new @json['camera']
  end

  if @json['film']
    @film       = Film.new @json['film']
  end

  if @json['longitude'] && @json['latitude']
    @longitude  = @json['location']['longitude']
    @latitude   = @json['location']['latitude']
  end
end

Instance Attribute Details

#cameraObject (readonly)

The camera attributes of the Photo

Returns:

  • Camera object



23
24
25
# File 'lib/rb-lomo/photo.rb', line 23

def camera
  @camera
end

#descriptionObject (readonly)

The description attribute of the Photo



14
15
16
# File 'lib/rb-lomo/photo.rb', line 14

def description
  @description
end

#filmObject (readonly)

The film attribute of the Photo

Returns:

  • Film object



28
29
30
# File 'lib/rb-lomo/photo.rb', line 28

def film
  @film
end

#idObject (readonly)

The ID attribute of the Photo



6
7
8
# File 'lib/rb-lomo/photo.rb', line 6

def id
  @id
end

#titleObject (readonly)

The title attribute of the Photo



10
11
12
# File 'lib/rb-lomo/photo.rb', line 10

def title
  @title
end

#urlObject (readonly)

The URL attribute of the Photo



18
19
20
# File 'lib/rb-lomo/photo.rb', line 18

def url
  @url
end

#userObject (readonly)

The user attribute of the Photo

Returns:

  • User object



33
34
35
# File 'lib/rb-lomo/photo.rb', line 33

def user
  @user
end

Instance Method Details

#large_asset_urlObject



75
76
77
# File 'lib/rb-lomo/photo.rb', line 75

def large_asset_url
  @json['assets']['large']['url']
end

#locationObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rb-lomo/photo.rb', line 59

def location

  if @longitude && @latitude
    {
      longitude: @longitude,
      latitude: @latitude
    }
  else
    'Location unknown'
  end
end

#sizeObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rb-lomo/photo.rb', line 79

def size
  {
    small: { 
      width: @json['assets']['small']['width'],
      height: @json['assets']['small']['height']
    },
    large: { 
      width: @json['assets']['large']['width'],
      height: @json['assets']['large']['height']
    }
  }
end

#small_asset_urlObject



71
72
73
# File 'lib/rb-lomo/photo.rb', line 71

def small_asset_url
  @json['assets']['small']['url']
end