Class: Travlrmap::Point
- Inherits:
-
Object
- Object
- Travlrmap::Point
- Defined in:
- lib/travlrmap/point.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #fetch(key, default) ⇒ Object
- #h(string) ⇒ Object
-
#initialize(from, types, type = :json) ⇒ Point
constructor
A new instance of Point.
- #preview ⇒ Object
- #to_hash ⇒ Object
- #to_html(title = true) ⇒ Object
- #to_json ⇒ Object
- #to_placemark ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(from, types, type = :json) ⇒ Point
Returns a new instance of Point.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/travlrmap/point.rb', line 3 def initialize(from, types, type=:json) @point = {} @types = types if from.is_a?(Hash) from_hash(from) elsif from.is_a?(String) if type == :json from_json(from) else from_yaml(from) end end end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/travlrmap/point.rb', line 31 def [](key) @point.fetch(key, nil) end |
#[]=(key, val) ⇒ Object
35 36 37 |
# File 'lib/travlrmap/point.rb', line 35 def []=(key, val) @point[key] = val end |
#fetch(key, default) ⇒ Object
39 40 41 |
# File 'lib/travlrmap/point.rb', line 39 def fetch(key, default) @point.fetch(key, default) end |
#h(string) ⇒ Object
27 28 29 |
# File 'lib/travlrmap/point.rb', line 27 def h(string) Rack::Utils.escape_html(string) end |
#preview ⇒ Object
18 19 20 21 |
# File 'lib/travlrmap/point.rb', line 18 def preview {"yaml" => YAML.dump([self.to_hash]).lines.to_a[1..-1].join, "html" => self.to_html} end |
#to_hash ⇒ Object
51 52 53 |
# File 'lib/travlrmap/point.rb', line 51 def to_hash @point.clone end |
#to_html(title = true) ⇒ Object
43 44 45 |
# File 'lib/travlrmap/point.rb', line 43 def to_html(title=true) ERB.new(point_html_template, nil, "<>").result(binding) end |
#to_json ⇒ Object
47 48 49 |
# File 'lib/travlrmap/point.rb', line 47 def to_json @point.to_json end |
#to_placemark ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/travlrmap/point.rb', line 55 def to_placemark KML::Placemark.new( :name => self[:title], :description => to_html(false), :geometry => KML::Point.new(:coordinates => {:lat => self[:lat], :lng => self[:lon]}), :style_url => "#%s" % Util.kml_style_url(self[:type], :type) ) end |
#type ⇒ Object
23 24 25 |
# File 'lib/travlrmap/point.rb', line 23 def type @types[ self[:type] ] end |