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.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/travlrmap/point.rb', line 4 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
32 33 34 |
# File 'lib/travlrmap/point.rb', line 32 def [](key) @point.fetch(key, nil) end |
#[]=(key, val) ⇒ Object
36 37 38 |
# File 'lib/travlrmap/point.rb', line 36 def []=(key, val) @point[key] = val end |
#fetch(key, default) ⇒ Object
40 41 42 |
# File 'lib/travlrmap/point.rb', line 40 def fetch(key, default) @point.fetch(key, default) end |
#h(string) ⇒ Object
28 29 30 |
# File 'lib/travlrmap/point.rb', line 28 def h(string) Rack::Utils.escape_html(string) end |
#preview ⇒ Object
19 20 21 22 |
# File 'lib/travlrmap/point.rb', line 19 def preview {"yaml" => YAML.dump([self.to_hash]).lines.to_a[1..-1].join, "html" => self.to_html} end |
#to_hash ⇒ Object
52 53 54 |
# File 'lib/travlrmap/point.rb', line 52 def to_hash @point.clone end |
#to_html(title = true) ⇒ Object
44 45 46 |
# File 'lib/travlrmap/point.rb', line 44 def to_html(title=true) ERB.new(point_html_template, nil, "<>").result(binding) end |
#to_json ⇒ Object
48 49 50 |
# File 'lib/travlrmap/point.rb', line 48 def to_json @point.to_json end |
#to_placemark ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/travlrmap/point.rb', line 56 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
24 25 26 |
# File 'lib/travlrmap/point.rb', line 24 def type @types[ self[:type] ] end |