Class: Crispy::Device

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/crispy-mobile/device.rb

Direct Known Subclasses

DesktopDevice

Constant Summary collapse

SUPPORTED_DISPLAY_WIDTHS =
{handheld_320: 320, handheld_640: 640, desktop: 950}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ Device

Returns a new instance of Device.



11
12
13
14
# File 'lib/crispy-mobile/device.rb', line 11

def initialize(profile)
  self.profile = profile
  self.display_width = profile.resolution_width
end

Instance Attribute Details

#display_widthObject

Returns the value of attribute display_width.



7
8
9
# File 'lib/crispy-mobile/device.rb', line 7

def display_width
  @display_width
end

#profileObject

Returns the value of attribute profile.



6
7
8
# File 'lib/crispy-mobile/device.rb', line 6

def profile
  @profile
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crispy-mobile/device.rb', line 20

def <=>(other)
  raise "Comparison of devices failed. Tried to compare #{self} with nil." if other.nil?

  other_width = if other.respond_to? :display_width
    other.display_width
  elsif other.respond_to?(:to_i) && other.to_i.integer?
    other.to_i
  elsif SUPPORTED_DISPLAY_WIDTHS.has_key? other
    SUPPORTED_DISPLAY_WIDTHS[other]
  end

  raise "Comparison of devices failed. No valid display_width can be infered from #{other}." unless other_width && other_width > 0
  display_width <=> other_width
end

#to_sObject



16
17
18
# File 'lib/crispy-mobile/device.rb', line 16

def to_s
  profile[:id]
end