Class: Lingo::Attendee::Formatter

Inherits:
TextWriter show all
Defined in:
lib/lingo/attendee/formatter.rb

Constant Summary

Constants included from TextUtils

TextUtils::DEFAULT_MODE, TextUtils::GZIP_RE, TextUtils::STDIN_EXT, TextUtils::STDOUT_EXT

Constants inherited from Lingo::Attendee

DEFAULT_SKIP, TERMINALS

Constants included from Language

Language::CHAR_PUNCT, Language::LA_SORTORDER, Language::TA_ABBREVIATION, Language::TA_HELP, Language::TA_HTML, Language::TA_NUMBER, Language::TA_OTHER, Language::TA_PUNCTUATION, Language::TA_SKIP, Language::TA_SPACE, Language::TA_URL, Language::TA_WIKI, Language::TA_WORD, Language::WA_COMPOUND, Language::WA_IDENTIFIED, Language::WA_MULTIWORD, Language::WA_SEQUENCE, Language::WA_UNKMULPART, Language::WA_UNKNOWN, Language::WA_UNSET

Instance Attribute Summary

Attributes inherited from Lingo::Attendee

#lingo, #subscribers

Instance Method Summary collapse

Methods inherited from TextWriter

#control

Methods inherited from Lingo::Attendee

#command, #forward, #initialize

Constructor Details

This class inherits a constructor from Lingo::Attendee

Instance Method Details

#initObject



33
34
35
36
37
38
39
40
41
# File 'lib/lingo/attendee/formatter.rb', line 33

def init
  super

  @ext    = get_key('ext', '-')
  @format = get_key('format', '%s')
  @map    = get_key('map', Hash.identity)

  @no_puts = true
end

#process(obj) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lingo/attendee/formatter.rb', line 43

def process(obj)
  if obj.is_a?(WordForm)
    str = obj.form

    if obj.is_a?(Word)
      # TODO: which lexical to select? (currently: first)
      obj.each_lex { |lex|
        att = @map[lex.attr] and str = @format % [str, lex.form, att] }
    end
  else
    str = obj.to_s
  end

  @lir ? @lir_rec_buf << str : @file.print(str)
end