require_relative '../lib/gepub/item.rb' attrs = GEPUB::Item::ATTRIBUTES.select do |attr| attr != 'href' end.map do |attr| attr.sub('-', '_') end attrs << "toc_text" attrs_arguments_string = attrs.map { |attr| "#{attr}: nil" }.join(',') attrs_internal_string = "{ " + attrs.map { |attr| "#{attr}: #{attr}"}.join(',') + " }" File.write(File.join(File.dirname(__FILE__), "../lib/gepub/book_add_item.rb"), <(content=UNASSIGNED, deprecated_id=nil, id:nil, #{refiners_arguments_string}, #{meta_attr_arguments_string}) { if unassigned?(content) get_first_node(node) else if deprecated_id warn "secound argument is deprecated. use id: keyword argument" id = deprecated_id end send(node + "_clear") add_metadata(node, content, id: id, #{refiners_arguments_set_string}, #{meta_attr_arguments_set_string}) end }) define_method(node+'=') { |content| send(node + "_clear") return if content.nil? if node == 'date' add_date(content) else add_metadata(node, content) end } next if ["identifier", "date", "creator", "contributor"].include?(node) define_method('add_' + node) { |content, id| add_metadata(node, content, id: id) } } def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil, #{refiners_arguments_string}, #{meta_attr_arguments_string}) if deprecated_id warn 'second argument for add_title is deprecated. use id: instead' id = deprecated_id end if deprecated_title_type warn 'third argument for add_title is deprecated. use title_type: instead' title_type = deprecated_title_type end meta = add_metadata('title', content, id: id, #{refiners_arguments_set_string}, #{meta_attr_arguments_set_string}) yield meta if block_given? meta end def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: nil, #{refiners_arguments_string}, #{meta_attr_arguments_string}) if deprecated_id warn 'second argument for add_person is deprecated. use id: instead' id = deprecated_id end if deprecated_role warn 'third argument for add_person is deprecated. use role: instead' role = deprecated_role end meta = add_metadata(name, content, id: id, #{refiners_arguments_set_string}, #{meta_attr_arguments_set_string}) yield meta if block_given? meta end def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil, #{refiners_arguments_string}, #{meta_attr_arguments_string}) if deprecated_id warn 'second argument for add_creator is deprecated. use id: instead' id = deprecated_id end if deprecated_role warn 'third argument for add_creator is deprecated. use role: instead' role = deprecated_role end role = 'aut' if role.nil? meta = add_person('creator', content, id: id, #{refiners_arguments_set_string}, #{meta_attr_arguments_set_string}) yield meta if block_given? meta end def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil, #{refiners_arguments_string}, #{meta_attr_arguments_string}) if deprecated_id warn 'second argument for add_contributor is deprecated. use id: instead' id = deprecated_id end if deprecated_role warn 'third argument for add_contributor is deprecated. use role: instead' role = deprecated_role end meta = add_person('contributor', content, id: id, #{refiners_arguments_set_string}, #{meta_attr_arguments_set_string}) yield meta if block_given? meta end def add_metadata(name, content, id: nil, itemclass: Meta, #{refiners_arguments_string}, #{meta_attr_arguments_string} ) meta = add_metadata_internal(name, content, id: id, itemclass: itemclass) #{refiners_string}.each do |refiner| if refiner[:value] meta.refine(refiner[:name], refiner[:value]) end end if lang meta.lang = lang end if alternates meta.add_alternates alternates end yield meta if block_given? meta end end end EOF