Class: Mida::Vocabulary

Inherits:
Object
  • Object
show all
Defined in:
lib/mida/vocabulary.rb

Overview

Class used to describe a vocabulary

To specify a vocabulary use the following methods: itemtype, has_one, has_many

Direct Known Subclasses

GenericVocabulary, SchemaOrg::AboutPage, SchemaOrg::AccountingService, SchemaOrg::AdministrativeArea, SchemaOrg::AdultEntertainment, SchemaOrg::AggregateOffer, SchemaOrg::AggregateRating, SchemaOrg::Airport, SchemaOrg::AmusementPark, SchemaOrg::AnimalShelter, SchemaOrg::ApartmentComplex, SchemaOrg::Aquarium, SchemaOrg::ArtGallery, SchemaOrg::Article, SchemaOrg::Attorney, SchemaOrg::AudioObject, SchemaOrg::AutoBodyShop, SchemaOrg::AutoDealer, SchemaOrg::AutoPartsStore, SchemaOrg::AutoRental, SchemaOrg::AutoRepair, SchemaOrg::AutoWash, SchemaOrg::AutomatedTeller, SchemaOrg::AutomotiveBusiness, SchemaOrg::Bakery, SchemaOrg::BankOrCreditUnion, SchemaOrg::BarOrPub, SchemaOrg::Beach, SchemaOrg::BeautySalon, SchemaOrg::BedAndBreakfast, SchemaOrg::BikeStore, SchemaOrg::Blog, SchemaOrg::BlogPosting, SchemaOrg::BodyOfWater, SchemaOrg::Book, SchemaOrg::BookStore, SchemaOrg::BowlingAlley, SchemaOrg::Brewery, SchemaOrg::BuddhistTemple, SchemaOrg::BusStation, SchemaOrg::BusStop, SchemaOrg::BusinessEvent, SchemaOrg::CafeOrCoffeeShop, SchemaOrg::Campground, SchemaOrg::Canal, SchemaOrg::Casino, SchemaOrg::CatholicChurch, SchemaOrg::Cemetery, SchemaOrg::CheckoutPage, SchemaOrg::ChildCare, SchemaOrg::ChildrensEvent, SchemaOrg::Church, SchemaOrg::City, SchemaOrg::CityHall, SchemaOrg::CivicStructure, SchemaOrg::ClothingStore, SchemaOrg::CollectionPage, SchemaOrg::CollegeOrUniversity, SchemaOrg::ComedyClub, SchemaOrg::ComedyEvent, SchemaOrg::ComputerStore, SchemaOrg::ContactPage, SchemaOrg::ContactPoint, SchemaOrg::Continent, SchemaOrg::ConvenienceStore, SchemaOrg::Corporation, SchemaOrg::Country, SchemaOrg::Courthouse, SchemaOrg::CreativeWork, SchemaOrg::Crematorium, SchemaOrg::DanceEvent, SchemaOrg::DanceGroup, SchemaOrg::DaySpa, SchemaOrg::DefenceEstablishment, SchemaOrg::Dentist, SchemaOrg::DepartmentStore, SchemaOrg::Distance, SchemaOrg::DryCleaningOrLaundry, SchemaOrg::Duration, SchemaOrg::EducationEvent, SchemaOrg::EducationalOrganization, SchemaOrg::Electrician, SchemaOrg::ElectronicsStore, SchemaOrg::ElementarySchool, SchemaOrg::Embassy, SchemaOrg::EmergencyService, SchemaOrg::EmploymentAgency, SchemaOrg::Energy, SchemaOrg::EntertainmentBusiness, SchemaOrg::Enumeration, SchemaOrg::Event, SchemaOrg::EventVenue, SchemaOrg::ExerciseGym, SchemaOrg::FastFoodRestaurant, SchemaOrg::Festival, SchemaOrg::FinancialService, SchemaOrg::FireStation, SchemaOrg::Florist, SchemaOrg::FoodEstablishment, SchemaOrg::FoodEvent, SchemaOrg::FurnitureStore, SchemaOrg::GardenStore, SchemaOrg::GasStation, SchemaOrg::GatedResidenceCommunity, SchemaOrg::GeneralContractor, SchemaOrg::GeoCoordinates, SchemaOrg::GolfCourse, SchemaOrg::GovernmentBuilding, SchemaOrg::GovernmentOffice, SchemaOrg::GovernmentOrganization, SchemaOrg::GroceryStore, SchemaOrg::HVACBusiness, SchemaOrg::HairSalon, SchemaOrg::HardwareStore, SchemaOrg::HealthAndBeautyBusiness, SchemaOrg::HealthClub, SchemaOrg::HighSchool, SchemaOrg::HinduTemple, SchemaOrg::HobbyShop, SchemaOrg::HomeAndConstructionBusiness, SchemaOrg::HomeGoodsStore, SchemaOrg::Hospital, SchemaOrg::Hostel, SchemaOrg::Hotel, SchemaOrg::HousePainter, SchemaOrg::IceCreamShop, SchemaOrg::ImageGallery, SchemaOrg::ImageObject, SchemaOrg::InsuranceAgency, SchemaOrg::Intangible, SchemaOrg::InternetCafe, SchemaOrg::ItemList, SchemaOrg::ItemPage, SchemaOrg::JewelryStore, SchemaOrg::LakeBodyOfWater, SchemaOrg::Landform, SchemaOrg::LandmarksOrHistoricalBuildings, SchemaOrg::Language, SchemaOrg::LegislativeBuilding, SchemaOrg::Library, SchemaOrg::LiquorStore, SchemaOrg::LiteraryEvent, SchemaOrg::LocalBusiness, SchemaOrg::Locksmith, SchemaOrg::LodgingBusiness, SchemaOrg::Map, SchemaOrg::Mass, SchemaOrg::MediaObject, SchemaOrg::MedicalClinic, SchemaOrg::MedicalOrganization, SchemaOrg::MensClothingStore, SchemaOrg::MiddleSchool, SchemaOrg::MobilePhoneStore, SchemaOrg::Mosque, SchemaOrg::Motel, SchemaOrg::MotorcycleDealer, SchemaOrg::MotorcycleRepair, SchemaOrg::Mountain, SchemaOrg::Movie, SchemaOrg::MovieRentalStore, SchemaOrg::MovieTheater, SchemaOrg::MovingCompany, SchemaOrg::Museum, SchemaOrg::MusicAlbum, SchemaOrg::MusicEvent, SchemaOrg::MusicGroup, SchemaOrg::MusicPlaylist, SchemaOrg::MusicRecording, SchemaOrg::MusicStore, SchemaOrg::MusicVenue, SchemaOrg::MusicVideoObject, SchemaOrg::NGO, SchemaOrg::NailSalon, SchemaOrg::NewsArticle, SchemaOrg::NightClub, SchemaOrg::Notary, SchemaOrg::NutritionInformation, SchemaOrg::OceanBodyOfWater, SchemaOrg::Offer, SchemaOrg::OfficeEquipmentStore, SchemaOrg::Optician, SchemaOrg::Organization, SchemaOrg::OutletStore, SchemaOrg::Painting, SchemaOrg::Park, SchemaOrg::ParkingFacility, SchemaOrg::PawnShop, SchemaOrg::PerformingArtsTheater, SchemaOrg::PerformingGroup, SchemaOrg::Person, SchemaOrg::PetStore, SchemaOrg::Pharmacy, SchemaOrg::Photograph, SchemaOrg::Physician, SchemaOrg::Place, SchemaOrg::PlaceOfWorship, SchemaOrg::Playground, SchemaOrg::Plumber, SchemaOrg::PoliceStation, SchemaOrg::Pond, SchemaOrg::PostOffice, SchemaOrg::PostalAddress, SchemaOrg::Preschool, SchemaOrg::Product, SchemaOrg::ProfessionalService, SchemaOrg::ProfilePage, SchemaOrg::PublicSwimmingPool, SchemaOrg::Quantity, SchemaOrg::RVPark, SchemaOrg::RadioStation, SchemaOrg::Rating, SchemaOrg::RealEstateAgent, SchemaOrg::Recipe, SchemaOrg::RecyclingCenter, SchemaOrg::Reservoir, SchemaOrg::Residence, SchemaOrg::Restaurant, SchemaOrg::Review, SchemaOrg::RiverBodyOfWater, SchemaOrg::RoofingContractor, SchemaOrg::SaleEvent, SchemaOrg::ScholarlyArticle, SchemaOrg::School, SchemaOrg::Sculpture, SchemaOrg::SeaBodyOfWater, SchemaOrg::SearchResultsPage, SchemaOrg::SelfStorage, SchemaOrg::ShoeStore, SchemaOrg::ShoppingCenter, SchemaOrg::SingleFamilyResidence, SchemaOrg::SiteNavigationElement, SchemaOrg::SkiResort, SchemaOrg::SocialEvent, SchemaOrg::SportingGoodsStore, SchemaOrg::SportsActivityLocation, SchemaOrg::SportsClub, SchemaOrg::SportsEvent, SchemaOrg::SportsTeam, SchemaOrg::StadiumOrArena, SchemaOrg::State, SchemaOrg::Store, SchemaOrg::StructuredValue, SchemaOrg::SubwayStation, SchemaOrg::Synagogue, SchemaOrg::TVEpisode, SchemaOrg::TVSeason, SchemaOrg::TVSeries, SchemaOrg::Table, SchemaOrg::TattooParlor, SchemaOrg::TaxiStand, SchemaOrg::TelevisionStation, SchemaOrg::TennisComplex, SchemaOrg::TheaterEvent, SchemaOrg::TheaterGroup, SchemaOrg::Thing, SchemaOrg::TireShop, SchemaOrg::TouristAttraction, SchemaOrg::TouristInformationCenter, SchemaOrg::ToyStore, SchemaOrg::TrainStation, SchemaOrg::TravelAgency, SchemaOrg::UserBlocks, SchemaOrg::UserCheckins, SchemaOrg::UserComments, SchemaOrg::UserDownloads, SchemaOrg::UserInteraction, SchemaOrg::UserLikes, SchemaOrg::UserPageVisits, SchemaOrg::UserPlays, SchemaOrg::UserPlusOnes, SchemaOrg::UserTweets, SchemaOrg::VeterinaryCare, SchemaOrg::VideoGallery, SchemaOrg::VideoObject, SchemaOrg::VisualArtsEvent, SchemaOrg::Volcano, SchemaOrg::WPAdBlock, SchemaOrg::WPFooter, SchemaOrg::WPHeader, SchemaOrg::WPSideBar, SchemaOrg::Waterfall, SchemaOrg::WebPage, SchemaOrg::WebPageElement, SchemaOrg::WholesaleStore, SchemaOrg::Winery, SchemaOrg::Zoo

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.vocabulariesObject (readonly)

Return the registered vocabularies



12
13
14
# File 'lib/mida/vocabulary.rb', line 12

def vocabularies
  @vocabularies
end

Class Method Details

.find(itemtype) ⇒ Object

Find the last vocabulary registered that matches the itemtype



29
30
31
32
33
34
# File 'lib/mida/vocabulary.rb', line 29

def self.find(itemtype)
  @vocabularies.reverse_each do |vocabulary|
    if ((itemtype || "") =~ vocabulary.itemtype) then return vocabulary end
  end
  nil
end

.has_many(*property_names, &block) ⇒ Object

Defines the properties as containing many values If want to say any property name, then use :any as a name Within a block you can use the methods of the class PropertyDesc



92
93
94
# File 'lib/mida/vocabulary.rb', line 92

def self.has_many(*property_names, &block)
  has(:many, *property_names, &block)
end

.has_one(*property_names, &block) ⇒ Object

Defines the properties as only containing one value If want to say any property name, then use :any as a name Within a block you can use the methods of the class PropertyDesc



85
86
87
# File 'lib/mida/vocabulary.rb', line 85

def self.has_one(*property_names, &block)
  has(:one, *property_names, &block)
end

.include_vocabulary(*vocabularies) ⇒ Object

Specify which vocabularies will have their properties included. This is the correct way to inherit properties from another vocabulary, rather than subclassing.



60
61
62
63
64
65
# File 'lib/mida/vocabulary.rb', line 60

def self.include_vocabulary(*vocabularies)
  vocabularies.each do |vocabulary|
    included_vocabularies.merge(vocabulary.included_vocabularies)
    included_vocabularies << vocabulary
  end
end

.included_vocabulariesObject

Return the included vocabularies



53
54
55
# File 'lib/mida/vocabulary.rb', line 53

def self.included_vocabularies
  @included_vocabularies ||= Set.new
end

.inherited(subclass) ⇒ Object



36
37
38
# File 'lib/mida/vocabulary.rb', line 36

def self.inherited(subclass)
  register(subclass)
end

.itemtype(regexp = nil) ⇒ Object

Sets the regular expression to match against the itemtype or returns the current regular expression



77
78
79
80
# File 'lib/mida/vocabulary.rb', line 77

def self.itemtype(regexp=nil)
  return @itemtype unless regexp
  @itemtype = regexp
end

.kind_of?(vocabulary) ⇒ Boolean

As per the standard kind_of?, but also checks to see if vocabulary has been included by self

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/mida/vocabulary.rb', line 69

def self.kind_of?(vocabulary)
  return true if self == vocabulary
  return true if self.ancestors.include?(vocabulary)
  included_vocabularies.include?(vocabulary)
end

.propertiesObject

Return the properties specification This won’t work properly until all the included_vocabularies have finished being defined in case of circular dependancies



43
44
45
46
47
48
49
50
# File 'lib/mida/vocabulary.rb', line 43

def self.properties
  return @properties if @properties
  @properties = @this_properties || {}
  included_vocabularies.each do |vocabulary|
    @properties.merge!(vocabulary.properties)
  end
  @properties
end

.register(vocabulary) ⇒ Object

Register a vocabulary that can be used when parsing, later vocabularies are given precedence over earlier ones



19
20
21
# File 'lib/mida/vocabulary.rb', line 19

def self.register(vocabulary)
  @vocabularies << vocabulary
end

.unregister(vocabulary) ⇒ Object

Un-register a vocabulary



24
25
26
# File 'lib/mida/vocabulary.rb', line 24

def self.unregister(vocabulary)
  @vocabularies.delete(vocabulary)
end