Class: YMaps::ActionView::YMapsBuilder

Inherits:
Builder
  • Object
show all
Defined in:
lib/ymaps/action_view/ymapsml_helper.rb

Direct Known Subclasses

YMapsReprBuilder

Constant Summary

Constants inherited from Builder

Builder::GML_TAG_NAMES, Builder::REPR_TAG_NAMES, Builder::YMAPS_TAG_NAMES

Instance Method Summary collapse

Constructor Details

#initialize(xml, view, ymaps_options = {}) ⇒ YMapsBuilder

Returns a new instance of YMapsBuilder.



67
68
69
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 67

def initialize(xml, view, ymaps_options = {})
  @xml, @view, @ymaps_options = xml, view, ymaps_options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class YMaps::ActionView::Builder

Instance Method Details

#bounds(bounds) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 99

def bounds(bounds)
  boundedBy {
    Envelope {
      lowerCorner(bounds.lower.gml_pos)
      upperCorner(bounds.upper.gml_pos)
    }
  } if bounds
end

#collection(options = {}) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 71

def collection(options = {})
  GeoObjectCollection do
    if options.key?(:style)
      @xml.style("\##{options.delete(:style)}")
    end
    featureMembers { yield }
  end
end

#meta_dataObject



108
109
110
111
112
113
114
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 108

def 
  metaDataProperty {
    AnyMetaData {
      yield(@xml)
    }
  }
end

#object(object, options = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 80

def object(object, options = {})
  gml_id = options.delete(:id) { object.id }
  GeoObject('gml:id' => gml_id) do
    if options.key?(:style)
      @xml.style("\##{options.delete(:style)}")
    end
    point(object.latlng) if object.respond_to?(:latlng)
    bounds(object.bounds) if object.respond_to?(:bounds)
    name(options.delete(:name) { object.to_s })
    yield self
  end
end

#point(latlng) ⇒ Object



93
94
95
96
97
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 93

def point(latlng)
  Point {
    pos(latlng.gml_pos)
  } if latlng
end

#representationObject



116
117
118
119
120
# File 'lib/ymaps/action_view/ymapsml_helper.rb', line 116

def representation
  Representation {
    yield(YMapsReprBuilder.new(@xml, @view))
  }
end