lib/csl/style.rb in csl-1.0.0.pre2 vs lib/csl/style.rb in csl-1.0.0.pre3
- old
+ new
@@ -1,8 +1,9 @@
module CSL
class Style < Node
+ types << CSL::Info << CSL::Locale
@default = :apa
@root = File.expand_path('../../../vendor/styles', __FILE__).freeze
@@ -19,11 +20,11 @@
raise ParseError, "root node is not a style: #{node.inspect}" unless
node.is_a?(self)
node
- end
+ end
end
attr_defaults :version => Schema.version, :xmlns => Schema.namespace
attr_struct :xmlns, :version, :class, :'default-locale',
@@ -31,20 +32,22 @@
:'demote-non-dropping-particle', *Schema.attr(:name, :names)
attr_children :'style-options', :info, :locale, :macro,
:citation, :bibliography
- alias metadata info
alias options style_options
alias locales locale
+ def_delegators :info, :self_link, :self_link=, :has_self_link?,
+ :template_link, :template_link=, :has_template_link?,
+ :documentation_link, :documentation_link=, :has_documentation_link?,
+ :title=, :id=
+
def initialize(attributes = {})
- super(attributes)
+ super(attributes, &nil)
+ children[:locale], children[:macro] = [], []
- children[:locale] = []
- children[:macro] = []
-
yield self if block_given?
end
def validate
Schema.validate self
@@ -52,13 +55,37 @@
def valid?
validate.empty?
end
+ def info
+ children[:info] ||= Info.new
+ end
+
+ alias_child :metadata, :info
+
+ # @return [String] the style's id
+ def id
+ return nil unless info.has_id?
+ info.id.to_s
+ end
+
+ # @return [String] the style's title
+ def title
+ return nil unless info.has_title?
+ info.title.to_s
+ end
+
+ # @return [Time] timestamp for the time set in info.updated
+ def updated_at
+ return nil unless info.has_updated?
+ Time.parse(info.updated)
+ end
+
private
def preamble
Schema.preamble.dup
end
end
-
+
end
\ No newline at end of file