class Terraformer::Primitive

abstract base class for terraformer objects. implements bbox and envelope.

Public Class Methods

new(*args) { |arg| ... } click to toggle source

handles basic JSON parsing for terraformer object constructors.

# File lib/terraformer.rb, line 74
def initialize *args
  arg = args[0]
  arg = JSON.parse(arg) if String === arg

  raise ArgumentError.new "invalid argument(s): #{args}" unless Hash === arg
  raise ArgumentError.new "invalid type: #{arg['type']}" unless arg['type'] == self.type
  yield arg if block_given?
end

Public Instance Methods

bbox(type = :bbox) click to toggle source

returns a bounding box array of values, with minimum axis values followed by maximum axis values.

# File lib/terraformer.rb, line 99
def bbox type = :bbox
  Bounds.bounds self.respond_to?(:geometry) ? self.geometry : self, type
end
envelope() click to toggle source

returns a bounding envelope as a Hash of the geometry. the envelope has keys for coordinates x and y, and dimensions w and h.

# File lib/terraformer.rb, line 92
def envelope
  Bounds.envelope self.respond_to?(:geometry) ? self.geometry : self
end
to_json(*args) click to toggle source

base to_json implementation for all terraformer objects.

# File lib/terraformer.rb, line 105
def to_json *args
  h = self.to_hash *args
  args.pop if Hash === args.last
  h.to_json *args
end
type() click to toggle source

terraformer object type as a String.

# File lib/terraformer.rb, line 85
def type
  self.class.to_s.sub 'Terraformer::', ''
end