Class: CSquare
- Inherits:
-
Object
- Object
- CSquare
- Defined in:
- lib/csquares/csquares.rb
Constant Summary collapse
- KM =
{10 => 0.1, 50 => 0.5, 100 => 1, 500 => 5, 1000 => 10}
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lng ⇒ Object
readonly
Returns the value of attribute lng.
Instance Method Summary collapse
-
#initialize(lat, lng) ⇒ CSquare
constructor
A new instance of CSquare.
- #sq(i = 0.1, int = false) ⇒ Object
Constructor Details
#initialize(lat, lng) ⇒ CSquare
Returns a new instance of CSquare.
7 8 9 10 11 12 13 14 |
# File 'lib/csquares/csquares.rb', line 7 def initialize(lat,lng) @lat, @lng = lat.to_f,lng.to_f digits = pad_and_interleave.insert(0,global_quadrant) chunks = chunk_up(digits) chunks[1..-1].each {|it| it.insert(0,intermediate_quadrant(it))} @code = delimit(chunks) @digits = chunks.join.split("").map {|it| it.to_i} end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/csquares/csquares.rb', line 3 def code @code end |
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
3 4 5 |
# File 'lib/csquares/csquares.rb', line 3 def digits @digits end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
3 4 5 |
# File 'lib/csquares/csquares.rb', line 3 def lat @lat end |
#lng ⇒ Object (readonly)
Returns the value of attribute lng.
3 4 5 |
# File 'lib/csquares/csquares.rb', line 3 def lng @lng end |
Instance Method Details
#sq(i = 0.1, int = false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/csquares/csquares.rb', line 16 def sq(i=0.1,int=false) n = 6 + (3 * Math.log10(i).abs).ceil it = case i when 10 then @digits[0..3] when 5 then @digits[0..4] when 1 then @digits[0..6] else @digits[0..n] end result = delimit [it[0..3],*it[4..-1].chunk_into(3)] int ? result.gsub(/:/){}.to_i : result end |