html_slicer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.1
2
+
3
+ * Code optimized for speed.
4
+
1
5
  == 0.1.0
2
6
 
3
7
  * The big changes. :)
@@ -68,9 +68,9 @@ module HtmlSlicer
68
68
  end
69
69
 
70
70
  def duplicate
71
- dup = Configuration.new
72
- dup.config.replace(deepcopy(config))
73
- dup
71
+ Configuration.new.tap do |c|
72
+ c.config.replace(deepcopy(config))
73
+ end
74
74
  end
75
75
 
76
76
  end
@@ -159,7 +159,7 @@ module HtmlSlicer
159
159
  when HTML::Text then
160
160
  if sliced?
161
161
  if range = slicing.map.get(node, slice)
162
- "#{node.content[Range.new(*range)]}#{slicing.options.text_break unless range.last == -1}"
162
+ "#{node.content[Range.new(*range)]}#{slicing.options.text_break unless range.last == -1 || !slicing.map.get(node, slice+1)}"
163
163
  end
164
164
  else
165
165
  node.to_s
@@ -37,24 +37,28 @@ module HtmlSlicer
37
37
  if sliceable?(node)
38
38
  sanitize_content!(node)
39
39
  content = node.to_s
40
- index = 0
41
40
  begin
42
- while (match = content.match(@options.unit, index)) && index < content.size
43
- units_count += 1
44
- last_index ||= 0
45
- if units_count == @options.maximum
46
- units_count = 0
47
- index = complete!(content, match.end(0))
48
- @map.commit(node, @slice_number, [last_index, index-1])
49
- last_index = index
50
- limited? ? raise(Exception) : @slice_number += 1
51
- else
52
- index = match.end(0)
53
- end
54
- if units_count > 0
55
- @map.commit(node, @slice_number, [last_index, -1])
41
+ start_index = 0
42
+ last_index = 0
43
+ content.scan(@options.unit) do
44
+ if $~.begin(0) >= start_index
45
+ units_count += 1
46
+ index = $~.end(0)
47
+ if units_count == @options.maximum
48
+ units_count = 0
49
+ if complete_regexp = @options.complete
50
+ index = content.match(complete_regexp, index).try(:begin, 0)||index
51
+ start_index = index
52
+ end
53
+ @map.commit(node, @slice_number, [last_index, index-1])
54
+ last_index = index
55
+ limited? ? raise(Exception) : @slice_number += 1
56
+ end
56
57
  end
57
58
  end
59
+ if units_count > 0
60
+ @map.commit(node, @slice_number, [last_index, -1])
61
+ end
58
62
  rescue Exception
59
63
  break
60
64
  end
@@ -94,14 +98,6 @@ module HtmlSlicer
94
98
  node.instance_variable_set(:@content, content)
95
99
  end
96
100
 
97
- def complete!(content, index)
98
- if regexp = @options.complete
99
- content.match(regexp, index).try(:begin, 0)||index
100
- else
101
- index
102
- end
103
- end
104
-
105
101
  def sliceable?(node)
106
102
  able_to?(node, @options)
107
103
  end
@@ -64,14 +64,13 @@ module HtmlSlicer
64
64
  raise(TypeError, "Array expected!") unless array.is_a?(Array)
65
65
  raise(Exception, "At least 2 elements needed!") if array.size < 2
66
66
  value = array.delete_at(-1)
67
- hash = {}
68
- index = 0
69
- last_hash = hash
70
- while index < array.size
71
- last_hash = last_hash[array.at(index)] = (index + 1 == array.size) ? value : {}
72
- index += 1
67
+ {}.tap do |hash|
68
+ index = 0
69
+ while index < array.size
70
+ hash = hash[array.at(index)] = (index + 1 == array.size) ? value : {}
71
+ index += 1
72
+ end
73
73
  end
74
- hash
75
74
  end
76
75
  end
77
76
 
@@ -1,3 +1,3 @@
1
1
  module HtmlSlicer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_slicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2012-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack