Class: CSL::Info

Inherits:
Node show all
Defined in:
lib/csl/info.rb

Overview

Info nodes contain a Style (or Locale) metadata. Their XML structure is based on the Atom Syndication Format. For independent styles an Info node typically has the following child elements:

  • Author and Contributor: used to respectively acknowledge style authors and contributors, may each be used multiple times.

  • Category: styles may be assigned one or more categories. One Category node may be used once to describe how in-text citations are rendered, using its citation-format attribute.

  • Id: Must appear once. The element should contain a URI to establish the identity of the style. A stable, unique and dereferenceable URI is desired for publicly available styles.

  • Link: Multiple links can be added to an Info node: self, documentation, and template links all have dedicated accessors.

  • Title: Must appear once. The contents of this node should be the name of the style as shown to users.

  • TitleShort: May appear once. The contents of this node should be a shortened style name (e.g. “APA”).

  • Summary: This node gives a description of the style.

  • Rights: This node specifies the license under which the style file is released. The element may carry a license attribute to specify the URI of the license.

  • Updated: Must appear once. This node must contain a timestamp that shows when the style was last updated.

In dependent styles, the Info node must contain a Link with rel set to “independent-parent”, with the URI of the independent parent style set on href. This link is also accessible as a string using the #independent_parent accessors. In addition, dependent styles should not contain template links.

In a Locale node the Info node typically carries only Translator, Rights and Updated nodes.

Defined Under Namespace

Classes: Author, Category, Contributor, DependentStyle, Email, Id, Link, Name, Published, Rights, Summary, Title, TitleShort, Translator, URI, Updated

Instance Attribute Summary collapse

Attributes inherited from Node

#attributes

Attributes included from Treelike

#children, #nodename, #parent

Instance Method Summary collapse

Methods inherited from Node

#<=>, #attribute?, #attributes?, #attributes_for, constantize, create, create_attributes, #custom_attributes, #deep_copy, #default_attribute?, #default_attributes, default_attributes, #each, #exact_match?, #format_page_ranges?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize_copy, #inspect, match?, #match?, matches?, #merge!, #page_range_format, parse, parse!, #quotes?, #reverse_merge!, #save_to, show_default_attributes!, #strip_periods?, #tags, #textnode?, types

Methods included from Extensions::Nesting

#nesting

Methods included from PrettyPrinter

#pretty_print, #tags, #to_xml

Methods included from Treelike

#<<, #add_child, #add_children, #ancestors, #closest, #delete_child, #delete_children, #depth, #descendants, #each_ancestor, #each_child, #each_descendant, #each_sibling, #empty?, #find_child, #find_children, #has_children?, #root, #root?, #siblings, #unlink

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Info

Returns a new instance of Info.

Yields:

  • (_self)

Yield Parameters:

  • _self (CSL::Info)

    the object that the method was called on



48
49
50
51
52
53
# File 'lib/csl/info.rb', line 48

def initialize(attributes = {})
  super(attributes, &nil)
  children[:link], children[:category] = [], []

  yield self if block_given?
end

Instance Attribute Details

Returns URI of style documentation.

Returns:

  • (String, nil)

    URI of style documentation



# File 'lib/csl/info.rb', line 61

Returns URI of independent-parent.

Returns:

  • (String, nil)

    URI of independent-parent



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/csl/info.rb', line 66

%w{ self template documentation independent-parent }.each do |type|
  method_id = "#{type.tr('-', '_')}_link"

  define_method method_id do
    link = links.detect { |l| l.match? :rel => type }
    link.nil? ? nil : link[:href]
  end

  alias_method "has_#{method_id}?", method_id

  define_method "#{method_id}=" do |value|
    link = links.detect { |l| l.match? :rel => type }

    if link.nil?
      set_child_link :href => value.to_s, :rel => type
    else
      link[:href] = value.to_s
      link
    end
  end
end

Returns the style’s URI.

Returns:

  • (String, nil)

    the style’s URI



# File 'lib/csl/info.rb', line 55

Returns URI of the style from which the current style is derived.

Returns:

  • (String, nil)

    URI of the style from which the current style is derived



# File 'lib/csl/info.rb', line 58

Instance Method Details

#citation_formatSymbol

Returns the parent style’s citation format.

Returns:

  • (Symbol)

    the parent style’s citation format



175
176
177
178
179
180
181
182
# File 'lib/csl/info.rb', line 175

def citation_format
  return unless has_categories?

  cat = categories.detect { |c| c.attribute? :'citation-format' }
  return if cat.nil?

  cat[:'citation-format'].to_sym
end

#citation_format=(new_format) ⇒ Object



184
185
186
187
188
189
# File 'lib/csl/info.rb', line 184

def citation_format=(new_format)
  cat = categories.detect { |c| c.attribute? :'citation-format' }
  cat = add_child Info::Category.new if cat.nil?

  cat[:'citation-format'] = new_format.to_s
end

#default_license!Object



163
164
165
166
167
168
169
170
171
172
# File 'lib/csl/info.rb', line 163

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

#default_license?Boolean

Returns:

  • (Boolean)


158
159
160
161
# File 'lib/csl/info.rb', line 158

def default_license?
  has_rights? && rights[:license] == Schema.default_license &&
    rights.text == Schema.default_rights_string
end

#idId

Returns the id text node.

Returns:

  • (Id)

    the id text node



94
95
96
# File 'lib/csl/info.rb', line 94

def id
  children[:id]
end

#licenseObject



145
146
147
148
# File 'lib/csl/info.rb', line 145

def license
  return unless has_rights?
  rights[:license] || rights.to_s
end

#license=(license) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/csl/info.rb', line 150

def license=(license)
  if has_rights?
    rights[:license] = license
  else
    add_child Rights.new(:license => license)
  end
end

#publish!(timestamp = Time.now) ⇒ self

Sets the updated_at timestamp.

Returns:

  • (self)


133
134
135
136
137
138
139
140
141
142
143
# File 'lib/csl/info.rb', line 133

def publish!(timestamp = Time.now)
  ts = timestamp.respond_to?(:xmlschema) ? timestamp.xmlschema : timestamp.to_s

  if has_published?
    published.text = ts
  else
    add_child Published.new { |u| u.text = ts }
  end

  self
end

#published_atTime?

Returns when the info node’s parent was published.

Returns:

  • (Time, nil)

    when the info node’s parent was published



126
127
128
129
# File 'lib/csl/info.rb', line 126

def published_at
  return unless has_published?
  published.to_time
end

#self_link!Object



100
101
102
103
# File 'lib/csl/info.rb', line 100

def self_link!
  return unless has_id?
  self.self_link = id
end

#update!(timestamp = Time.now) ⇒ self

Sets the updated_at timestamp.

Returns:

  • (self)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/csl/info.rb', line 113

def update!(timestamp = Time.now)
  ts = timestamp.respond_to?(:xmlschema) ? timestamp.xmlschema : timestamp.to_s

  if has_updated?
    updated.text = ts
  else
    add_child Updated.new { |u| u.text = ts }
  end

  self
end

#updated_atTime?

Returns when the info node’s parent was last updated.

Returns:

  • (Time, nil)

    when the info node’s parent was last updated



106
107
108
109
# File 'lib/csl/info.rb', line 106

def updated_at
  return unless has_updated?
  updated.to_time
end