lib/inat/data/entity/observation.rb in inat-get-0.8.0.12 vs lib/inat/data/entity/observation.rb in inat-get-0.8.0.13

- old
+ new

@@ -6,31 +6,38 @@ require_relative '../entity' require_relative '../enums/qualitygrade' require_relative '../enums/licensecode' require_relative '../enums/geoprivacy' -autoload :Taxon, 'inat/data/entity/taxon' -autoload :User, 'inat/data/entity/user' -autoload :Flag, 'inat/data/entity/flag' -autoload :ObservationSound, 'inat/data/entity/observationsound' -autoload :Sound, 'inat/data/entity/sound' -autoload :ObservationPhoto, 'inat/data/entity/observationphoto' -autoload :Photo, 'inat/data/entity/photo' -autoload :Place, 'inat/data/entity/place' -autoload :Project, 'inat/data/entity/project' -autoload :Comment, 'inat/data/entity/comment' -autoload :Identification, 'inat/data/entity/identification' -autoload :Vote, 'inat/data/entity/vote' +module INat::Entity + autoload :Taxon, 'inat/data/entity/taxon' + autoload :User, 'inat/data/entity/user' + autoload :Flag, 'inat/data/entity/flag' + autoload :ObservationSound, 'inat/data/entity/observationsound' + autoload :Sound, 'inat/data/entity/sound' + autoload :ObservationPhoto, 'inat/data/entity/observationphoto' + autoload :Photo, 'inat/data/entity/photo' + autoload :Place, 'inat/data/entity/place' + autoload :Project, 'inat/data/entity/project' + autoload :Comment, 'inat/data/entity/comment' + autoload :Identification, 'inat/data/entity/identification' + autoload :Vote, 'inat/data/entity/vote' +end -class Observation < Entity +class INat::Entity::Observation < INat::Data::Entity + include INat::Data::Types + include INat::Entity + api_path :observations api_part :query api_limit 200 table :observations + # @!group Fields + field :quality_grade, type: QualityGrade, required: true, index: true field :uuid, type: UUID, unique: true field :species_guess, type: String field :license_code, type: LicenseCode, index: true field :description, type: String @@ -99,10 +106,14 @@ field :taxon_is_active, type: Boolean, index: true field :threatened, type: Boolean, index: true field :photo_licensed, type: Boolean, index: true field :rank, type: Rank, index: true + # @!endgroup + + # @!group Callbacks + def post_update t = self.taxon if t self.endemic = t.endemic self.introduced = t.introduced @@ -113,9 +124,11 @@ end if self.observation_photos != nil self.photo_licensed = self.observation_photos.any? { |p| p.photo.license_code != nil } end end + + # @!endgroup def normalized_taxon ranks ranks = (ranks .. ranks) if Rank === ranks raise TypeError, "Invalid type for ranks: #{ ranks.inspect }!", caller unless Range === ranks min = ranks.begin