Class: GeoHex::Unit
- Inherits:
-
Object
- Object
- GeoHex::Unit
- Defined in:
- lib/geo_hex/unit.rb
Overview
A Unit is a class of Zones. It has a ‘level`, `width`, `height` and overall `size`. Dimensions vary for different levels.
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Class Method Summary collapse
-
.[](level) ⇒ GeoHex::Unit
For the given level.
- .cache=(value) ⇒ Object
-
.cache? ⇒ Boolean
True if unit caching is enabled, defaults to false.
-
.store ⇒ Hash
Cache store.
Instance Method Summary collapse
-
#height ⇒ Float
Unit’s mercator height.
-
#initialize(level) ⇒ Unit
constructor
A new instance of Unit.
-
#size ⇒ Float
Unit’s mercator size.
-
#width ⇒ Float
Unit’s mercator width.
Constructor Details
#initialize(level) ⇒ Unit
Returns a new instance of Unit.
36 37 38 |
# File 'lib/geo_hex/unit.rb', line 36 def initialize(level) @level = level end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
33 34 35 |
# File 'lib/geo_hex/unit.rb', line 33 def level @level end |
Class Method Details
.[](level) ⇒ GeoHex::Unit
Returns for the given level.
27 28 29 |
# File 'lib/geo_hex/unit.rb', line 27 def [](level) cache? ? store[level] ||= new(level) : new(level) end |
.cache=(value) ⇒ Object
16 17 18 |
# File 'lib/geo_hex/unit.rb', line 16 def cache=(value) @cache = value end |
.cache? ⇒ Boolean
Returns true if unit caching is enabled, defaults to false.
11 12 13 |
# File 'lib/geo_hex/unit.rb', line 11 def cache? @cache == true end |
.store ⇒ Hash
Returns cache store.
21 22 23 |
# File 'lib/geo_hex/unit.rb', line 21 def store @store ||= {} end |
Instance Method Details
#height ⇒ Float
Returns unit’s mercator height.
51 52 53 |
# File 'lib/geo_hex/unit.rb', line 51 def height @height ||= width * H_K end |
#size ⇒ Float
Returns unit’s mercator size.
41 42 43 |
# File 'lib/geo_hex/unit.rb', line 41 def size @size ||= H_BASE / 3**(level+3) end |
#width ⇒ Float
Returns unit’s mercator width.
46 47 48 |
# File 'lib/geo_hex/unit.rb', line 46 def width @width ||= 6.0 * size end |