Class: Mida::Vocabulary
- Inherits:
-
Object
- Object
- Mida::Vocabulary
- Defined in:
- lib/mida_vocabulary/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
DataVocabulary::Address, DataVocabulary::Breadcrumb, DataVocabulary::Event, DataVocabulary::Geo, DataVocabulary::Item, DataVocabulary::Offer, DataVocabulary::OfferAggregate, DataVocabulary::Organization, DataVocabulary::Person, DataVocabulary::Product, DataVocabulary::Recipe, DataVocabulary::Review, GenericVocabulary, SchemaOrg::APIReference, SchemaOrg::AboutPage, SchemaOrg::AcceptAction, SchemaOrg::AccountingService, SchemaOrg::AchieveAction, SchemaOrg::Action, SchemaOrg::AddAction, SchemaOrg::AdministrativeArea, SchemaOrg::AdultEntertainment, SchemaOrg::AggregateOffer, SchemaOrg::AggregateRating, SchemaOrg::AgreeAction, SchemaOrg::Airline, SchemaOrg::Airport, SchemaOrg::AlignmentObject, SchemaOrg::AllocateAction, SchemaOrg::AmusementPark, SchemaOrg::AnatomicalStructure, SchemaOrg::AnatomicalSystem, SchemaOrg::AnimalShelter, SchemaOrg::Answer, SchemaOrg::ApartmentComplex, SchemaOrg::AppendAction, SchemaOrg::ApplyAction, SchemaOrg::ApprovedIndication, SchemaOrg::Aquarium, SchemaOrg::ArriveAction, SchemaOrg::ArtGallery, SchemaOrg::Artery, SchemaOrg::Article, SchemaOrg::AskAction, SchemaOrg::AssessAction, SchemaOrg::AssignAction, SchemaOrg::Attorney, SchemaOrg::Audience, SchemaOrg::AudioObject, SchemaOrg::AuthorizeAction, 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::BefriendAction, SchemaOrg::BikeStore, SchemaOrg::BlogPosting, SchemaOrg::BloodTest, SchemaOrg::BodyOfWater, SchemaOrg::Bone, SchemaOrg::Book, SchemaOrg::BookStore, SchemaOrg::BookmarkAction, SchemaOrg::BorrowAction, SchemaOrg::BowlingAlley, SchemaOrg::BrainStructure, SchemaOrg::Brand, SchemaOrg::Brewery, SchemaOrg::BroadcastEvent, SchemaOrg::BroadcastService, SchemaOrg::BuddhistTemple, SchemaOrg::BusReservation, SchemaOrg::BusStation, SchemaOrg::BusStop, SchemaOrg::BusTrip, SchemaOrg::BusinessAudience, SchemaOrg::BusinessEvent, SchemaOrg::BuyAction, SchemaOrg::CafeOrCoffeeShop, SchemaOrg::Campground, SchemaOrg::Canal, SchemaOrg::CancelAction, SchemaOrg::Car, SchemaOrg::Casino, SchemaOrg::CatholicChurch, SchemaOrg::Cemetery, SchemaOrg::CheckAction, SchemaOrg::CheckInAction, SchemaOrg::CheckOutAction, SchemaOrg::CheckoutPage, SchemaOrg::ChildCare, SchemaOrg::ChildrensEvent, SchemaOrg::ChooseAction, SchemaOrg::Church, SchemaOrg::City, SchemaOrg::CityHall, SchemaOrg::CivicStructure, SchemaOrg::Class, SchemaOrg::Clip, SchemaOrg::ClothingStore, SchemaOrg::Code, SchemaOrg::CollectionPage, SchemaOrg::CollegeOrUniversity, SchemaOrg::ComedyClub, SchemaOrg::ComedyEvent, SchemaOrg::Comment, SchemaOrg::CommentAction, SchemaOrg::CommunicateAction, SchemaOrg::ComputerStore, SchemaOrg::ConfirmAction, SchemaOrg::ConsumeAction, SchemaOrg::ContactPage, SchemaOrg::ContactPoint, SchemaOrg::Continent, SchemaOrg::ConvenienceStore, SchemaOrg::CookAction, SchemaOrg::Corporation, SchemaOrg::Country, SchemaOrg::Courthouse, SchemaOrg::CreateAction, SchemaOrg::CreativeWork, SchemaOrg::Crematorium, SchemaOrg::DDxElement, SchemaOrg::DanceEvent, SchemaOrg::DanceGroup, SchemaOrg::DataCatalog, SchemaOrg::DataDownload, SchemaOrg::Dataset, SchemaOrg::DaySpa, SchemaOrg::DefenceEstablishment, SchemaOrg::DeleteAction, SchemaOrg::DeliveryChargeSpecification, SchemaOrg::DeliveryEvent, SchemaOrg::Demand, SchemaOrg::Dentist, SchemaOrg::DepartAction, SchemaOrg::DepartmentStore, SchemaOrg::DiagnosticLab, SchemaOrg::DiagnosticProcedure, SchemaOrg::Diet, SchemaOrg::DietarySupplement, SchemaOrg::DisagreeAction, SchemaOrg::DiscoverAction, SchemaOrg::DislikeAction, SchemaOrg::Distance, SchemaOrg::DonateAction, SchemaOrg::DoseSchedule, SchemaOrg::DownloadAction, SchemaOrg::DrawAction, SchemaOrg::DrinkAction, SchemaOrg::Drug, SchemaOrg::DrugClass, SchemaOrg::DrugCost, SchemaOrg::DrugLegalStatus, SchemaOrg::DrugStrength, SchemaOrg::DryCleaningOrLaundry, SchemaOrg::Duration, SchemaOrg::EatAction, SchemaOrg::EducationEvent, SchemaOrg::EducationalAudience, SchemaOrg::EducationalOrganization, SchemaOrg::Electrician, SchemaOrg::ElectronicsStore, SchemaOrg::ElementarySchool, SchemaOrg::EmailMessage, SchemaOrg::Embassy, SchemaOrg::EmergencyService, SchemaOrg::EmploymentAgency, SchemaOrg::EndorseAction, SchemaOrg::Energy, SchemaOrg::EntertainmentBusiness, SchemaOrg::Enumeration, SchemaOrg::Episode, SchemaOrg::Event, SchemaOrg::EventReservation, SchemaOrg::EventVenue, SchemaOrg::ExerciseAction, SchemaOrg::ExerciseGym, SchemaOrg::ExercisePlan, SchemaOrg::FastFoodRestaurant, SchemaOrg::Festival, SchemaOrg::FilmAction, SchemaOrg::FinancialService, SchemaOrg::FindAction, SchemaOrg::FireStation, SchemaOrg::Flight, SchemaOrg::FlightReservation, SchemaOrg::Florist, SchemaOrg::FollowAction, SchemaOrg::FoodEstablishment, SchemaOrg::FoodEstablishmentReservation, SchemaOrg::FoodEvent, SchemaOrg::FurnitureStore, SchemaOrg::GardenStore, SchemaOrg::GasStation, SchemaOrg::GatedResidenceCommunity, SchemaOrg::GeneralContractor, SchemaOrg::GeoCoordinates, SchemaOrg::GeoShape, SchemaOrg::GiveAction, SchemaOrg::GolfCourse, SchemaOrg::GovernmentBuilding, SchemaOrg::GovernmentOffice, SchemaOrg::GovernmentOrganization, SchemaOrg::GovernmentPermit, SchemaOrg::GovernmentService, 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::IgnoreAction, SchemaOrg::ImageGallery, SchemaOrg::ImageObject, SchemaOrg::ImagingTest, SchemaOrg::IndividualProduct, SchemaOrg::InfectiousDisease, SchemaOrg::InformAction, SchemaOrg::InsertAction, SchemaOrg::InstallAction, SchemaOrg::InsuranceAgency, SchemaOrg::Intangible, SchemaOrg::InteractAction, SchemaOrg::InternetCafe, SchemaOrg::InviteAction, SchemaOrg::ItemList, SchemaOrg::ItemPage, SchemaOrg::JewelryStore, SchemaOrg::JobPosting, SchemaOrg::JoinAction, SchemaOrg::Joint, SchemaOrg::LakeBodyOfWater, SchemaOrg::Landform, SchemaOrg::LandmarksOrHistoricalBuildings, SchemaOrg::Language, SchemaOrg::LeaveAction, SchemaOrg::LegislativeBuilding, SchemaOrg::LendAction, SchemaOrg::Library, SchemaOrg::LifestyleModification, SchemaOrg::Ligament, SchemaOrg::LikeAction, SchemaOrg::LiquorStore, SchemaOrg::ListenAction, SchemaOrg::LiteraryEvent, SchemaOrg::LocalBusiness, SchemaOrg::Locksmith, SchemaOrg::LodgingBusiness, SchemaOrg::LodgingReservation, SchemaOrg::LoseAction, SchemaOrg::LymphaticVessel, SchemaOrg::Map, SchemaOrg::MarryAction, SchemaOrg::Mass, SchemaOrg::MaximumDoseSchedule, SchemaOrg::MediaObject, SchemaOrg::MedicalCause, SchemaOrg::MedicalClinic, SchemaOrg::MedicalCode, SchemaOrg::MedicalCondition, SchemaOrg::MedicalConditionStage, SchemaOrg::MedicalContraindication, SchemaOrg::MedicalDevice, SchemaOrg::MedicalEntity, SchemaOrg::MedicalGuideline, SchemaOrg::MedicalGuidelineContraindication, SchemaOrg::MedicalGuidelineRecommendation, SchemaOrg::MedicalIndication, SchemaOrg::MedicalIntangible, SchemaOrg::MedicalObservationalStudy, SchemaOrg::MedicalOrganization, SchemaOrg::MedicalProcedure, SchemaOrg::MedicalRiskCalculator, SchemaOrg::MedicalRiskEstimator, SchemaOrg::MedicalRiskFactor, SchemaOrg::MedicalRiskScore, SchemaOrg::MedicalScholarlyArticle, SchemaOrg::MedicalSign, SchemaOrg::MedicalSignOrSymptom, SchemaOrg::MedicalStudy, SchemaOrg::MedicalSymptom, SchemaOrg::MedicalTest, SchemaOrg::MedicalTestPanel, SchemaOrg::MedicalTherapy, SchemaOrg::MedicalTrial, SchemaOrg::MedicalWebPage, SchemaOrg::MensClothingStore, SchemaOrg::MiddleSchool, SchemaOrg::MobileApplication, SchemaOrg::MobilePhoneStore, SchemaOrg::Mosque, SchemaOrg::Motel, SchemaOrg::MotorcycleDealer, SchemaOrg::MotorcycleRepair, SchemaOrg::Mountain, SchemaOrg::MoveAction, SchemaOrg::Movie, SchemaOrg::MovieRentalStore, SchemaOrg::MovieTheater, SchemaOrg::MovingCompany, SchemaOrg::Muscle, SchemaOrg::Museum, SchemaOrg::MusicAlbum, SchemaOrg::MusicEvent, SchemaOrg::MusicGroup, SchemaOrg::MusicPlaylist, SchemaOrg::MusicRecording, SchemaOrg::MusicStore, SchemaOrg::MusicVenue, SchemaOrg::MusicVideoObject, SchemaOrg::NGO, SchemaOrg::NailSalon, SchemaOrg::Nerve, SchemaOrg::NewsArticle, SchemaOrg::NightClub, SchemaOrg::Notary, SchemaOrg::NutritionInformation, SchemaOrg::OceanBodyOfWater, SchemaOrg::Offer, SchemaOrg::OfficeEquipmentStore, SchemaOrg::OnDemandEvent, SchemaOrg::OpeningHoursSpecification, SchemaOrg::Optician, SchemaOrg::Order, SchemaOrg::OrderAction, SchemaOrg::Organization, SchemaOrg::OrganizeAction, SchemaOrg::OutletStore, SchemaOrg::OwnershipInfo, SchemaOrg::PaintAction, SchemaOrg::Painting, SchemaOrg::PalliativeProcedure, SchemaOrg::ParcelDelivery, SchemaOrg::ParentAudience, SchemaOrg::Park, SchemaOrg::ParkingFacility, SchemaOrg::PathologyTest, SchemaOrg::PawnShop, SchemaOrg::PayAction, SchemaOrg::PaymentChargeSpecification, SchemaOrg::PeopleAudience, SchemaOrg::PerformAction, SchemaOrg::PerformingArtsTheater, SchemaOrg::PerformingGroup, SchemaOrg::Periodical, SchemaOrg::Permit, SchemaOrg::Person, SchemaOrg::PetStore, SchemaOrg::Pharmacy, SchemaOrg::Photograph, SchemaOrg::PhotographAction, SchemaOrg::PhysicalActivity, SchemaOrg::PhysicalTherapy, SchemaOrg::Physician, SchemaOrg::Place, SchemaOrg::PlaceOfWorship, SchemaOrg::PlanAction, SchemaOrg::PlayAction, SchemaOrg::Playground, SchemaOrg::Plumber, SchemaOrg::PoliceStation, SchemaOrg::Pond, SchemaOrg::PostOffice, SchemaOrg::PostalAddress, SchemaOrg::PrependAction, SchemaOrg::Preschool, SchemaOrg::PreventionIndication, SchemaOrg::PriceSpecification, SchemaOrg::Product, SchemaOrg::ProductModel, SchemaOrg::ProfessionalService, SchemaOrg::ProfilePage, SchemaOrg::ProgramMembership, SchemaOrg::Property, SchemaOrg::PsychologicalTreatment, SchemaOrg::PublicSwimmingPool, SchemaOrg::PublicationEvent, SchemaOrg::PublicationIssue, SchemaOrg::PublicationVolume, SchemaOrg::QAPage, SchemaOrg::QuantitativeValue, SchemaOrg::Quantity, SchemaOrg::Question, SchemaOrg::QuoteAction, SchemaOrg::RVPark, SchemaOrg::RadiationTherapy, SchemaOrg::RadioClip, SchemaOrg::RadioEpisode, SchemaOrg::RadioSeason, SchemaOrg::RadioSeries, SchemaOrg::RadioStation, SchemaOrg::Rating, SchemaOrg::ReactAction, SchemaOrg::ReadAction, SchemaOrg::RealEstateAgent, SchemaOrg::ReceiveAction, SchemaOrg::Recipe, SchemaOrg::RecommendedDoseSchedule, SchemaOrg::RecyclingCenter, SchemaOrg::RegisterAction, SchemaOrg::RejectAction, SchemaOrg::RentAction, SchemaOrg::RentalCarReservation, SchemaOrg::ReplaceAction, SchemaOrg::ReplyAction, SchemaOrg::ReportedDoseSchedule, SchemaOrg::Reservation, SchemaOrg::ReservationPackage, SchemaOrg::ReserveAction, SchemaOrg::Reservoir, SchemaOrg::Residence, SchemaOrg::Restaurant, SchemaOrg::ReturnAction, SchemaOrg::Review, SchemaOrg::ReviewAction, SchemaOrg::RiverBodyOfWater, SchemaOrg::RoofingContractor, SchemaOrg::RsvpAction, SchemaOrg::SaleEvent, SchemaOrg::ScheduleAction, SchemaOrg::ScholarlyArticle, SchemaOrg::School, SchemaOrg::Sculpture, SchemaOrg::SeaBodyOfWater, SchemaOrg::SearchAction, SchemaOrg::SearchResultsPage, SchemaOrg::Season, SchemaOrg::Seat, SchemaOrg::SelfStorage, SchemaOrg::SellAction, SchemaOrg::SendAction, SchemaOrg::Series, SchemaOrg::Service, SchemaOrg::ServiceChannel, SchemaOrg::ShareAction, SchemaOrg::ShoeStore, SchemaOrg::ShoppingCenter, SchemaOrg::SingleFamilyResidence, SchemaOrg::SiteNavigationElement, SchemaOrg::SkiResort, SchemaOrg::SocialEvent, SchemaOrg::SoftwareApplication, SchemaOrg::SomeProducts, SchemaOrg::SportingGoodsStore, SchemaOrg::SportsActivityLocation, SchemaOrg::SportsClub, SchemaOrg::SportsEvent, SchemaOrg::SportsTeam, SchemaOrg::StadiumOrArena, SchemaOrg::State, SchemaOrg::Store, SchemaOrg::StructuredValue, SchemaOrg::SubscribeAction, SchemaOrg::SubwayStation, SchemaOrg::SuperficialAnatomy, SchemaOrg::Synagogue, SchemaOrg::TVClip, SchemaOrg::TVEpisode, SchemaOrg::TVSeason, SchemaOrg::TVSeries, SchemaOrg::Table, SchemaOrg::TakeAction, SchemaOrg::TattooParlor, SchemaOrg::Taxi, SchemaOrg::TaxiReservation, SchemaOrg::TaxiStand, SchemaOrg::TechArticle, SchemaOrg::TelevisionStation, SchemaOrg::TennisComplex, SchemaOrg::TheaterEvent, SchemaOrg::TheaterGroup, SchemaOrg::TherapeuticProcedure, SchemaOrg::Thing, SchemaOrg::Ticket, SchemaOrg::TieAction, SchemaOrg::TipAction, SchemaOrg::TireShop, SchemaOrg::TouristAttraction, SchemaOrg::TouristInformationCenter, SchemaOrg::ToyStore, SchemaOrg::TrackAction, SchemaOrg::TradeAction, SchemaOrg::TrainReservation, SchemaOrg::TrainStation, SchemaOrg::TrainTrip, SchemaOrg::TransferAction, SchemaOrg::TravelAction, SchemaOrg::TravelAgency, SchemaOrg::TreatmentIndication, SchemaOrg::TypeAndQuantityNode, SchemaOrg::UnRegisterAction, SchemaOrg::UnitPriceSpecification, SchemaOrg::UpdateAction, SchemaOrg::UseAction, SchemaOrg::UserBlocks, SchemaOrg::UserCheckins, SchemaOrg::UserComments, SchemaOrg::UserDownloads, SchemaOrg::UserInteraction, SchemaOrg::UserLikes, SchemaOrg::UserPageVisits, SchemaOrg::UserPlays, SchemaOrg::UserPlusOnes, SchemaOrg::UserTweets, SchemaOrg::Vehicle, SchemaOrg::Vein, SchemaOrg::Vessel, SchemaOrg::VeterinaryCare, SchemaOrg::VideoGallery, SchemaOrg::VideoObject, SchemaOrg::ViewAction, SchemaOrg::VisualArtsEvent, SchemaOrg::Volcano, SchemaOrg::VoteAction, SchemaOrg::WPAdBlock, SchemaOrg::WPFooter, SchemaOrg::WPHeader, SchemaOrg::WPSideBar, SchemaOrg::WantAction, SchemaOrg::WarrantyPromise, SchemaOrg::WatchAction, SchemaOrg::Waterfall, SchemaOrg::WearAction, SchemaOrg::WebApplication, SchemaOrg::WebPage, SchemaOrg::WebPageElement, SchemaOrg::WholesaleStore, SchemaOrg::WinAction, SchemaOrg::Winery, SchemaOrg::WriteAction, SchemaOrg::Zoo
Class Attribute Summary collapse
-
.vocabularies ⇒ Object
readonly
Return the registered vocabularies.
Class Method Summary collapse
- .camel_case(string) ⇒ Object
-
.find(itemtype) ⇒ Object
Find the last vocabulary registered that matches the itemtype.
-
.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 classPropertyDesc
. -
.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 classPropertyDesc
. -
.include_vocabulary(*vocabularies) ⇒ Object
Specify which
vocabularies
will have their properties included. -
.included_vocabularies ⇒ Object
Return the included vocabularies.
- .inherited(subclass) ⇒ Object
-
.itemtype(regexp = nil) ⇒ Object
Sets the regular expression to match against the
itemtype
or returns the current regular expression. -
.kind_of?(vocabulary) ⇒ Boolean
As per the standard
kind_of?
, but also checks to see if vocabulary has been included by self. -
.properties ⇒ Object
Return the properties specification This won’t work properly until all the included_vocabularies have finished being defined in case of circular dependancies.
-
.register(vocabulary) ⇒ Object
Register a vocabulary that can be used when parsing, later vocabularies are given precedence over earlier ones.
-
.try_load_const(item_type) ⇒ Object
It convert name to const name and try to find it in autload directory.
-
.unregister(vocabulary) ⇒ Object
Un-register a vocabulary.
Class Attribute Details
.vocabularies ⇒ Object (readonly)
Return the registered vocabularies
13 14 15 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 13 def vocabularies @vocabularies end |
Class Method Details
.camel_case(string) ⇒ Object
77 78 79 80 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 77 def self.camel_case(string) return string if string !~ /_/ && string =~ /[A-Z]+.*/ string.split('_').map {|e| e.capitalize }.join end |
.find(itemtype) ⇒ Object
Find the last vocabulary registered that matches the itemtype
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 30 def self.find(itemtype) if const = try_load_const(itemtype) return const else @vocabularies.sort_by {|v| v.itemtype ? v.itemtype.source.size : 0 }.reverse.each do |vocabulary| if ((itemtype || "") =~ vocabulary.itemtype) return vocabulary end 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
138 139 140 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 138 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
131 132 133 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 131 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.
106 107 108 109 110 111 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 106 def self.include_vocabulary(*vocabularies) vocabularies.each do |vocabulary| included_vocabularies.merge(vocabulary.included_vocabularies) included_vocabularies << vocabulary end end |
.included_vocabularies ⇒ Object
Return the included vocabularies
99 100 101 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 99 def self.included_vocabularies @included_vocabularies ||= Set.new end |
.inherited(subclass) ⇒ Object
82 83 84 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 82 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
123 124 125 126 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 123 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
115 116 117 118 119 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 115 def self.kind_of?(vocabulary) return true if self == vocabulary return true if self.ancestors.include?(vocabulary) included_vocabularies.include?(vocabulary) end |
.properties ⇒ Object
Return the properties specification This won’t work properly until all the included_vocabularies have finished being defined in case of circular dependancies
89 90 91 92 93 94 95 96 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 89 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
20 21 22 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 20 def self.register(vocabulary) @vocabularies << vocabulary end |
.try_load_const(item_type) ⇒ Object
It convert name to const name and try to find it in autload directory
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 44 def self.try_load_const(item_type) # http://schema.org/Winery => winery # http://schema.org/AutomotiveBusiness => automotivebusiness # http://data-vocabulary.org/Offer-aggregate/ => offeraggregate if item_type =~ /https?:\/\// uri = URI.parse(item_type) if uri.host != 'schema.org' && uri.host != 'data-vocabulary.org' return nil end item_type = uri.path.gsub('/', '').gsub('-', '') end constName = camel_case(item_type) if Mida::SchemaOrg.const_defined?(constName, false) return Mida::SchemaOrg.const_get(constName, false) end if Mida::DataVocabulary.const_defined?(constName, false) return Mida::DataVocabulary.const_get(constName, false) end load_path = File.dirname(__FILE__) + "/vocabularies/schemaorg/#{constName.downcase}.rb" if File.exist?(load_path) return Mida::SchemaOrg.const_get(constName, false) # hit autoloader end load_path = File.dirname(__FILE__) + "/vocabularies/data_vocabulary/#{constName.downcase}.rb" if File.exist?(load_path) return Mida::DataVocabulary.const_get(constName, false) # hit autoloader end end |
.unregister(vocabulary) ⇒ Object
Un-register a vocabulary
25 26 27 |
# File 'lib/mida_vocabulary/vocabulary.rb', line 25 def self.unregister(vocabulary) @vocabularies.delete(vocabulary) end |