Class: HtmlSlicer::Helpers::Slicer::SliceProxy

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/html_slicer/helpers/slicer.rb

Overview

Wraps a “slice number” and provides some utility methods

Instance Method Summary collapse

Constructor Details

#initialize(options, slice, last) ⇒ SliceProxy

:nodoc:



108
109
110
# File 'lib/html_slicer/helpers/slicer.rb', line 108

def initialize(options, slice, last) #:nodoc:
  @options, @slice, @last = options, slice, last
end

Instance Method Details

#+(other) ⇒ Object



170
171
172
# File 'lib/html_slicer/helpers/slicer.rb', line 170

def +(other)
  to_i + other.to_i
end

#-(other) ⇒ Object



174
175
176
# File 'lib/html_slicer/helpers/slicer.rb', line 174

def -(other)
  to_i - other.to_i
end

#<=>(other) ⇒ Object



178
179
180
# File 'lib/html_slicer/helpers/slicer.rb', line 178

def <=>(other)
  to_i <=> other.to_i
end

#current?Boolean

current slice or not

Returns:

  • (Boolean)


118
119
120
# File 'lib/html_slicer/helpers/slicer.rb', line 118

def current?
  @slice == @options[:current_slice]
end

#first?Boolean

the first slice or not

Returns:

  • (Boolean)


123
124
125
# File 'lib/html_slicer/helpers/slicer.rb', line 123

def first?
  @slice == 1
end

#inside_window?Boolean

inside the inner window or not

Returns:

  • (Boolean)


153
154
155
# File 'lib/html_slicer/helpers/slicer.rb', line 153

def inside_window?
  (@options[:current_slice] - @slice).abs <= @options[:window]
end

#last?Boolean

the last slice or not

Returns:

  • (Boolean)


128
129
130
# File 'lib/html_slicer/helpers/slicer.rb', line 128

def last?
  @slice == @options[:slice_number]
end

#left_outer?Boolean

within the left outer window or not

Returns:

  • (Boolean)


143
144
145
# File 'lib/html_slicer/helpers/slicer.rb', line 143

def left_outer?
  @slice <= @options[:left]
end

#next?Boolean

the next slice or not

Returns:

  • (Boolean)


138
139
140
# File 'lib/html_slicer/helpers/slicer.rb', line 138

def next?
  @slice == @options[:current_slice] + 1
end

#numberObject

the slice number



113
114
115
# File 'lib/html_slicer/helpers/slicer.rb', line 113

def number
  @slice
end

#prev?Boolean

the previous slice or not

Returns:

  • (Boolean)


133
134
135
# File 'lib/html_slicer/helpers/slicer.rb', line 133

def prev?
  @slice == @options[:current_slice] - 1
end

#right_outer?Boolean

within the right outer window or not

Returns:

  • (Boolean)


148
149
150
# File 'lib/html_slicer/helpers/slicer.rb', line 148

def right_outer?
  @options[:slice_number] - @slice < @options[:right]
end

#to_iObject



162
163
164
# File 'lib/html_slicer/helpers/slicer.rb', line 162

def to_i
  number
end

#to_sObject



166
167
168
# File 'lib/html_slicer/helpers/slicer.rb', line 166

def to_s
  number.to_s
end

#was_truncated?Boolean

The last rendered tag was “truncated” or not

Returns:

  • (Boolean)


158
159
160
# File 'lib/html_slicer/helpers/slicer.rb', line 158

def was_truncated?
  @last.is_a? Gap
end