Class: About_Pos::Meta

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

Overview

class self ===

Instance Method Summary collapse

Constructor Details

#initialize(dir, real_index, i, arr, prev = nil) ⇒ Meta

Returns a new instance of Meta.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/about_pos.rb', line 41

def initialize dir, real_index, i, arr, prev = nil
  @arr        = arr
  @data       = {}
  @dir        = dir
  @last_index = arr.size - 1

  @real_index = real_index
  @value      = arr[real_index]
  @i          = i

  @next = nil
  @prev = prev
end

Instance Method Details

#[](k) ⇒ Object



143
144
145
# File 'lib/about_pos.rb', line 143

def [] k
  @data[k]
end

#[]=(k, v) ⇒ Object



147
148
149
# File 'lib/about_pos.rb', line 147

def []= k, v
  @data[k] = v
end

#back?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/about_pos.rb', line 107

def back?
  dir == :back
end

#bottom?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/about_pos.rb', line 139

def bottom?
  real_index == last_index
end

#dirObject



103
104
105
# File 'lib/about_pos.rb', line 103

def dir
  @dir
end

#forward?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/about_pos.rb', line 111

def forward?
  dir == :forward
end

#middle?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/about_pos.rb', line 135

def middle?
  real_index != 0 && real_index != last_index
end

#nextObject

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/about_pos.rb', line 69

def next
  @msg ||= if forward?
             "This is the last position."
           else
             "This is the first position."
           end
  raise No_Next, @msg if !next?

  @next ||= begin
              if forward?
                Meta.new(dir, real_index + 1, self.i + 1, arr, self)
              else
                Meta.new(dir, real_index - 1, self.i - 1, arr, self)
              end
            end
end

#next?Boolean

Returns:

  • (Boolean)


115
116
117
118
119
120
121
# File 'lib/about_pos.rb', line 115

def next?
  if forward?
    real_index != last_index
  else
    real_index != 0
  end
end

#prevObject

Raises:



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

def prev
  @msg ||= if forward?
             "This is the first position."
           else
             "This is the last position."
           end
  raise No_Prev, @msg if !prev?

  @prev ||= begin
              if forward?
                Meta.new(dir, real_index - 1, self.i - 1, arr)
              else
                Meta.new(dir, real_index + 1, self.i + 1, arr)
              end
            end
end

#prev?Boolean

Returns:

  • (Boolean)


123
124
125
126
127
128
129
# File 'lib/about_pos.rb', line 123

def prev?
  if forward?
    real_index != 0
  else
    real_index != last_index
  end
end

#top?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/about_pos.rb', line 131

def top?
  real_index == 0
end