lib/csl/info.rb in csl-1.0.0.pre21 vs lib/csl/info.rb in csl-1.0.0.pre22

- old
+ new

@@ -35,11 +35,11 @@ # {Rights} and {Updated} nodes. class Info < Node attr_children :title, :'title-short', :id, :issn, :eissn, :issnl, :link, :author, :contributor, :translator, :category, :published, - :summary, :updated, :rights, :'link-dependent-style' + :summary, :updated, :rights, :'link-dependent-style' alias_child :contributors, :contributor alias_child :authors, :author alias_child :translators, :translator alias_child :links, :link @@ -94,10 +94,15 @@ children[:id] end alias id= set_child_id + def self_link! + return unless has_id? + self.self_link = id + end + # @return [Time,nil] when the info node's parent was last updated def updated_at return unless has_updated? updated.to_time end @@ -106,13 +111,13 @@ # @return [self] def update!(timestamp = Time.now) ts = timestamp.respond_to?(:xmlschema) ? timestamp.xmlschema : timestamp.to_s if has_updated? - updated = Updated.new { |u| u.text = ts } - else updated.text = ts + else + add_child Updated.new { |u| u.text = ts } end self end @@ -126,18 +131,47 @@ # @return [self] def publish!(timestamp = Time.now) ts = timestamp.respond_to?(:xmlschema) ? timestamp.xmlschema : timestamp.to_s if has_published? - published = Published.new { |u| u.text = ts } - else published.text = ts + else + add_child Published.new { |u| u.text = ts } end self end + def license + return unless has_rights? + rights[:license] || rights.to_s + end + + def license=(license) + if has_rights? + rights[:license] = license + else + add_child Rights.new(:license => license) + end + end + + def default_license? + has_rights? && rights[:license] == Schema.default_license && + rights.to_s == Schema.default_rights_string + end + + def default_license! + if has_rights? + rights[:license] = Schema.default_license + rights.text = Schema.default_rights_string + else + add_child Rights.new(:license => Schema.default_license) { |r| + r.text = Schema.default_rights_string + } + end + end + # @return [Symbol] the parent style's citation format def citation_format return unless has_categories? cat = categories.detect { |c| c.attribute? :'citation-format' } @@ -157,25 +191,25 @@ # Info Child Nodes # class Contributor < Node attr_children :name, :email, :uri - def_delegators :name, *Namae::Name.members + def_delegators :name, *Namae::Name.members end class Author < Node attr_children :name, :email, :uri - def_delegators :name, *Namae::Name.members + def_delegators :name, *Namae::Name.members end class Translator < Node attr_children :name, :email, :uri - def_delegators :name, *Namae::Name.members + def_delegators :name, *Namae::Name.members end class Link < Node - has_language + has_language attr_struct :href, :rel end class DependentStyle < TextNode attr_struct :href, :rel @@ -189,42 +223,42 @@ class Id < TextNode end class Name < TextNode - def_delegators :namae, *Namae::Name.members + def_delegators :namae, *Namae::Name.members - private + private - def namae - @namae || namae! - end + def namae + @namae || namae! + end - def namae! - @namae = Namae::Name.parse to_s - end + def namae! + @namae = Namae::Name.parse to_s + end end class Email < TextNode end class URI < TextNode end class Title < TextNode - has_language + has_language end class TitleShort < TextNode - has_language + has_language end class Summary < TextNode - has_language + has_language end class Rights < TextNode - has_language + has_language attr_struct :license end class Updated < TextNode def to_time \ No newline at end of file