class MyJohnDeere::Field
Public Class Methods
new(json_object, access_token = nil)
click to toggle source
Calls superclass method
# File lib/myjohndeere/field.rb, line 8 def initialize(json_object, access_token = nil) @boundary = nil super(json_object, access_token) boundaries = json_object["boundaries"] if boundaries && boundaries.length > 0 then # If we embed, then we'll need to pass our id possible_boundaries = boundaries.map { |b_json| Boundary.new(b_json, access_token, self.id) } self.boundary = find_first_active_boundary(possible_boundaries) end end
Public Instance Methods
boundary()
click to toggle source
# File lib/myjohndeere/field.rb, line 25 def boundary if self.boundary_unset? then boundaries = Boundary.list(self.access_token, field_id: self.id, organization_id: self.organization_id) @boundary = find_first_active_boundary(boundaries.data) end return @boundary end
boundary=(val)
click to toggle source
# File lib/myjohndeere/field.rb, line 33 def boundary=(val) @boundary = val end
boundary_unset?()
click to toggle source
Will return whether or not the boundary has been set, useful if you're expecting embedded boundaries
# File lib/myjohndeere/field.rb, line 21 def boundary_unset? return @boundary.nil? end
Private Instance Methods
find_first_active_boundary(possible_boundaries)
click to toggle source
# File lib/myjohndeere/field.rb, line 38 def find_first_active_boundary(possible_boundaries) active_boundaries = possible_boundaries.select { |b| b.active && !b.deleted }. uniq { |b| b.id } if active_boundaries.count > 1 then if MyJohnDeere.configuration.use_last_active_boundary then MyJohnDeere.logger.info("Multiple boundaries found for field ID: #{self.id}. Using last active") return active_boundaries.last else raise MyJohnDeereError.new("There was more than one boundary in the field ID: #{self.id}, this is currently unexpected") end elsif active_boundaries.count == 1 then return active_boundaries.first else return possible_boundaries.first end end