DRY up the logic to create new property classes.
Take some code that was duplicated in both the PropertyParser and Format classes and move into a method in the Property module.
This commit is contained in:
parent
e8d9e77e41
commit
65fb44239c
3 changed files with 15 additions and 13 deletions
|
@ -33,13 +33,7 @@ module Microformats2
|
|||
end
|
||||
|
||||
def add_property(property_class, value)
|
||||
# NOTE: Might want to DRY this up with what is in PropertyParser
|
||||
prefix = property_class.split("-").first
|
||||
# find ruby class for kind of property
|
||||
klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix]
|
||||
raise InvalidPropertyPrefix unless klass
|
||||
# We don't have a nokogiri element so pass in nil
|
||||
property = klass.new(nil, property_class, value)
|
||||
property = Property.new(nil, property_class, value)
|
||||
assign_property(property)
|
||||
end
|
||||
|
||||
|
|
|
@ -6,5 +6,18 @@ module Microformats2
|
|||
"u" => Url,
|
||||
"dt" => DateTime,
|
||||
"e" => Embedded }
|
||||
|
||||
class << self
|
||||
|
||||
def new(element, property_class, value=nil)
|
||||
# p-class-name -> p
|
||||
prefix = property_class.split("-").first
|
||||
# find ruby class for kind of property
|
||||
klass = PREFIX_CLASS_MAP[prefix]
|
||||
raise InvalidPropertyPrefix unless klass
|
||||
klass.new(element, property_class, value)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,12 +26,7 @@ module Microformats2
|
|||
|
||||
def parse_property(element)
|
||||
property_classes(element).map do |property_class|
|
||||
# p-class-name -> p
|
||||
prefix = property_class.split("-").first
|
||||
# find ruby class for kind of property
|
||||
klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix]
|
||||
|
||||
property = klass.new(element, property_class).parse
|
||||
property = Property.new(element, property_class).parse
|
||||
properties = format_classes(element).empty? ? PropertyParser.parse(element.children) : []
|
||||
|
||||
[property].concat properties
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue