Class: Scholar::Source

Inherits:
Utilities show all
Defined in:
lib/scholar/source.rb

Overview

The basis for sources. Inherit from this class to create other types of sources.

Direct Known Subclasses

Scholar::Sources::Book

Class Method Summary collapse

Methods included from Utilities::Formatters

#capitalize, #carets, #colon, #comma, #italicize, #ordinal, #period, #quotes, #replace, #underline

Methods included from Utilities::Data

#concatenate!, #contributors!, #format!, #order!

Class Method Details

.rule(key, &action) ⇒ Object

Defines a specific action to be taken on an attribute.

Attributes

  • key - The key of the hash to take the action on. Symbol.

  • action - The action to take on the key. Should be a method within Scholar::Utilities::Formatters.



51
52
53
# File 'lib/scholar/source.rb', line 51

def rule(key, &action)
  @@rules << [key, action]
end

.rules(&block) ⇒ Object

Defines what actions need to be taken on the attributes.

Attributes

  • block - A block of rule definitions. The rule definition should call a method in Scholar::Utilities::Formatters.

Example

rules do
  rule(:foo) {|v| italicize(v) }
end


34
35
36
37
38
39
40
41
42
# File 'lib/scholar/source.rb', line 34

def rules(&block)
  if block
    @@rules ||= []

    self.class_eval(&block)
  else
    self.descendants.empty? ? @@rules : nil
  end
end

.sequence(arr = nil) ⇒ Object

Defines the order of attributes for Sources.

Attributes

  • arr - Array of Symbols (keys). This is the order the hash’s key will be in.



14
15
16
17
18
19
20
# File 'lib/scholar/source.rb', line 14

def sequence(arr = nil)
  unless arr.nil?
    @@sequence = arr
  end

  self.descendants.empty? ? @@sequence : nil
end