Module: Rea::Command::Utils

Included in:
Search
Defined in:
lib/rea/command/utils.rb

Constant Summary collapse

DEFAULT_INFO =
{
  :title   => "[Unknown title]",
  :authors => ["[Unknown author]"],
  :year    => "[Unknown year]",
  :key     => "[Unknown key]",
  :source  => "[Unknown source]",
}

Instance Method Summary collapse

Instance Method Details

#pretty(rel, keep = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rea/command/utils.rb', line 13

def pretty(rel, keep = nil)
  keep ||= [:code, :key, :author, :title, :year, :source]
  Relation(rel).
    defaults(DEFAULT_INFO).
    extend(:authors => lambda{
      authors.empty? ? ["[Unknown author]"] : authors
    }).
    extend(
      :code   => lambda{ authors.first.split(/\s/).last + year.to_s },
      :title  => lambda{ title[0..50]  },
      :author => lambda{ authors.first }
    ).project(keep)
rescue
  Relation(rel).project(keep)
end