Class: Metadata::Formats::String

Inherits:
Base
  • Object
show all
Defined in:
lib/metadata/formats/string.rb

Constant Summary collapse

DICTIONARY =
{
  'is' => {
    present: 'is',
    past: 'was'
  }
}

Instance Attribute Summary

Attributes inherited from Base

#object, #output

Instance Method Summary collapse

Methods inherited from Base

#about, #puts

Constructor Details

#initialize(object, &block) ⇒ String

Returns a new instance of String.



12
13
14
15
# File 'lib/metadata/formats/string.rb', line 12

def initialize(object, &block)
  @next = {}
  super(object, &block)
end

Instance Method Details

#and_Object



52
53
54
# File 'lib/metadata/formats/string.rb', line 52

def and_
  @output << word(:and)
end

#around(*args) ⇒ Object



48
49
50
# File 'lib/metadata/formats/string.rb', line 48

def around(*args)
  @output << statement(word(:around), args.first)
end

#is(something, tense = :present) ⇒ Object



17
18
19
20
21
# File 'lib/metadata/formats/string.rb', line 17

def is(something, tense=:present)
  something = pairs(something) if something.is_a?(Hash)
  
  @output << statement(change_tense(word(:is), tense), something)
end

#it(something) ⇒ Object



27
28
29
30
31
# File 'lib/metadata/formats/string.rb', line 27

def it(something)
  something = pairs(something) if something.is_a?(Hash)
  
  @output << statement(word(:it), something)
end

#stopObject



43
44
45
46
# File 'lib/metadata/formats/string.rb', line 43

def stop        
  @output << "."
  @next[:capitalize] = true
end

#to_sObject



56
57
58
# File 'lib/metadata/formats/string.rb', line 56

def to_s
  statement(*@output)
end

#was(something) ⇒ Object



23
24
25
# File 'lib/metadata/formats/string.rb', line 23

def was(something)
  is(something, :past)
end

#with(hash) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/metadata/formats/string.rb', line 33

def with(hash)
  @output << ::String.new.tap do |s|
    hash.map do |k,v|
      k = k.to_s
      k = k.singularize if k.respond_to? :singularize and v == 1
      s << statement(word(:with), v, k)
    end
  end
end