Class: Crispy::Device
- Inherits:
-
Object
- Object
- Crispy::Device
- Includes:
- Comparable
- Defined in:
- lib/crispy-mobile/device.rb
Direct Known Subclasses
Constant Summary collapse
- SUPPORTED_DISPLAY_WIDTHS =
{handheld_320: 320, handheld_640: 640, desktop: 950}
Instance Attribute Summary collapse
-
#display_width ⇒ Object
Returns the value of attribute display_width.
-
#profile ⇒ Object
Returns the value of attribute profile.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(profile) ⇒ Device
constructor
A new instance of Device.
- #to_s ⇒ Object
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_width ⇒ Object
Returns the value of attribute display_width.
7 8 9 |
# File 'lib/crispy-mobile/device.rb', line 7 def display_width @display_width end |
#profile ⇒ Object
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_s ⇒ Object
16 17 18 |
# File 'lib/crispy-mobile/device.rb', line 16 def to_s profile[:id] end |