Class: ProgramR::History

Inherits:
Object
  • Object
show all
Defined in:
lib/programr/history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHistory

Returns a new instance of History.


5
6
7
8
9
10
11
12
# File 'lib/programr/history.rb', line 5

def initialize
  @topic       = 'undef'
  @inputs      = []
  @responses   = []
  @star_greedy  = []
  @that_greedy  = []
  @topic_greedy = []
end

Instance Attribute Details

#topicObject

Returns the value of attribute topic


3
4
5
# File 'lib/programr/history.rb', line 3

def topic
  @topic
end

Instance Method Details

#beforethatString

Return last second input or 'undef'

Returns:

  • (String)

    return last second input or 'undef'


58
59
60
61
# File 'lib/programr/history.rb', line 58

def beforethat
  return 'undef' unless @inputs[1]
  @inputs[1]
end

#get_response(index) ⇒ String?

Parameters:

  • index (Numeric)

    get response, 0 is the nearest one

Returns:

  • (String, nil)

29
30
31
# File 'lib/programr/history.rb', line 29

def get_response index
  @responses[index]
end

#get_star(index) ⇒ String

Parameters:

  • index (Numeric)

    get star, 0 is the nearest one

Returns:

  • (String)

66
67
68
69
# File 'lib/programr/history.rb', line 66

def get_star index
  return 'undef' unless @star_greedy[index]
  @star_greedy[index].join(' ')
end

#get_stimula(index) ⇒ String?

Parameters:

  • index (Numeric)

    get stimula, 0 is the nearest one

Returns:

  • (String, nil)

17
18
19
# File 'lib/programr/history.rb', line 17

def get_stimula index
  @inputs[index]
end

#get_thatstar(index) ⇒ String

Parameters:

  • index (Numeric)

    get thatstar, 0 is the nearest one

Returns:

  • (String)

73
74
75
76
# File 'lib/programr/history.rb', line 73

def get_thatstar index
  return 'undef' unless @that_greedy[index]
  @that_greedy[index].join(' ')
end

#get_topicstar(index) ⇒ String

Parameters:

  • index (Numeric)

    get topicstar, 0 is the nearest one

Returns:

  • (String)

80
81
82
83
# File 'lib/programr/history.rb', line 80

def get_topicstar index
  return 'undef' unless @topic_greedy[index]
  @topic_greedy[index].join(' ')
end

#justbeforethatString

Return last second response or 'undef'

Returns:

  • (String)

    return last second response or 'undef'


46
47
48
49
# File 'lib/programr/history.rb', line 46

def justbeforethat
  return 'undef' unless @responses[1]
  @responses[1]
end

#justthatString

Return last input or 'undef'

Returns:

  • (String)

    return last input or 'undef'


52
53
54
55
# File 'lib/programr/history.rb', line 52

def justthat
  return 'undef' unless @inputs[0]
  @inputs[0]
end

#thatString

Return last response or 'undef'

Returns:

  • (String)

    return last response or 'undef'


40
41
42
43
# File 'lib/programr/history.rb', line 40

def that
  return 'undef' unless @responses[0]
  @responses[0]
end

#update_response(response) ⇒ Object

Parameters:

  • response (String)

34
35
36
# File 'lib/programr/history.rb', line 34

def update_response response
  @responses.unshift response
end

#update_star_matches(star_greedy_array) ⇒ Object

Parameters:

  • star_greedy_array (Array<String>)

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/programr/history.rb', line 86

def update_star_matches star_greedy_array
  @star_greedy = []
  @that_greedy = []
  @topic_greedy = []
  current_greedy = @star_greedy
  star_greedy_array.each do |greedy|
    if greedy == GraphMark::THAT
      current_greedy = @that_greedy
    elsif greedy == GraphMark::TOPIC
      current_greedy = @topic_greedy
    elsif greedy == '<star>'
      current_greedy.push([])
    else
      current_greedy.last.push(greedy)
    end
  end
end

#update_stimula(stimula) ⇒ Object

Parameters:

  • stimula (String)

22
23
24
# File 'lib/programr/history.rb', line 22

def update_stimula stimula
  @inputs.unshift stimula
end