Class: Remedy::Size
- Inherits:
-
Object
- Object
- Remedy::Size
- Defined in:
- lib/remedy/size.rb
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
Returns the value of attribute dimensions.
Class Method Summary collapse
Instance Method Summary collapse
- #-(other_size) ⇒ Object
- #/(value) ⇒ Object
- #<<(value) ⇒ Object
- #[](index) ⇒ Object
- #cols ⇒ Object (also: #columns, #width)
- #fits_into?(size_to_fit_into) ⇒ Boolean
-
#initialize(*new_dimensions) ⇒ Size
constructor
A new instance of Size.
- #inspect ⇒ Object
- #length ⇒ Object
- #rows ⇒ Object (also: #height)
- #to_a ⇒ Object
- #to_ary ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*new_dimensions) ⇒ Size
Returns a new instance of Size.
3 4 5 6 7 8 9 10 11 |
# File 'lib/remedy/size.rb', line 3 def initialize *new_dimensions new_dimensions.flatten! if new_dimensions.first.is_a? Range then new_dimensions.map! do |range| range.to_a.length end end @dimensions = new_dimensions end |
Instance Attribute Details
#dimensions ⇒ Object
Returns the value of attribute dimensions.
12 13 14 |
# File 'lib/remedy/size.rb', line 12 def dimensions @dimensions end |
Class Method Details
.zero ⇒ Object
14 15 16 |
# File 'lib/remedy/size.rb', line 14 def self.zero self.new([0,0]) end |
Instance Method Details
#-(other_size) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/remedy/size.rb', line 18 def - other_size if other_size.respond_to? :length then self.class.new subtract(other_size) else self.class.new deduct(other_size) end end |
#/(value) ⇒ Object
26 27 28 29 30 |
# File 'lib/remedy/size.rb', line 26 def / value dimensions.map do |dimension| dimension / value end end |
#<<(value) ⇒ Object
32 33 34 |
# File 'lib/remedy/size.rb', line 32 def << value self.dimensions << value end |
#[](index) ⇒ Object
56 57 58 |
# File 'lib/remedy/size.rb', line 56 def [] index dimensions[index] end |
#cols ⇒ Object Also known as: columns, width
50 51 52 |
# File 'lib/remedy/size.rb', line 50 def cols dimensions[1] end |
#fits_into?(size_to_fit_into) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/remedy/size.rb', line 37 def fits_into? size_to_fit_into other_size = Size(size_to_fit_into) length.times.each do |index| return false if self[index] > other_size[index] end true end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/remedy/size.rb', line 76 def inspect "#<#{self.class}:#{to_s}>" end |
#length ⇒ Object
60 61 62 |
# File 'lib/remedy/size.rb', line 60 def length dimensions.length end |
#rows ⇒ Object Also known as: height
45 46 47 |
# File 'lib/remedy/size.rb', line 45 def rows dimensions[0] end |
#to_a ⇒ Object
64 65 66 |
# File 'lib/remedy/size.rb', line 64 def to_a dimensions.dup end |
#to_ary ⇒ Object
68 69 70 |
# File 'lib/remedy/size.rb', line 68 def to_ary dimensions end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/remedy/size.rb', line 72 def to_s "(#{dimensions.join('x')})" end |