rbhtml 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/rbhtml.rb +15 -1
  2. metadata +3 -3
data/lib/rbhtml.rb CHANGED
@@ -19,6 +19,7 @@ class HTMLDocument
19
19
  @full_doc = @open_doc + @close_doc
20
20
  @index_dict = {}
21
21
  @index_id = 0
22
+ @count = {}
22
23
  end
23
24
  def create_element tag, inner, attribute=false, value=false
24
25
  if attribute and value
@@ -27,18 +28,31 @@ class HTMLDocument
27
28
  @open_doc += "<#{tag}>#{inner}</#{tag}>"
28
29
  end
29
30
  @index_id += 1
31
+ if @count.keys.include? tag
32
+ @count[tag] += 1
33
+ else
34
+ @count[tag] = 1
35
+ end
30
36
  refresh_full
31
37
  index_element tag, inner
32
38
  end
33
39
  def remove_element tag, inner
34
- @open_doc.gsub!("<#{tag}>#{inner}", "")
40
+ if @open_doc.gsub!("<#{tag}>#{inner}</#{tag}>", "") == nil
41
+ return
42
+ else
43
+ @open_doc.gsub!("<#{tag}>#{inner}</#{tag}>", "")
44
+ end
35
45
  @close_doc.gsub!("</#{tag}>", "")
46
+ @count[tag] -= 1
36
47
  refresh_full
37
48
  end
38
49
  def remove_char char
39
50
  @open_doc.gsub!(">#{char}", ">")
40
51
  refresh_full
41
52
  end
53
+ def count tag
54
+ @count[tag]
55
+ end
42
56
  def to_s
43
57
  @full_doc
44
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbhtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,8 +11,8 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-06-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: An HTML generator written in Ruby. Added attributes to create_element
15
- method. Removed bug where if you create two elements, the elements overlap.
14
+ description: An HTML generator written in Ruby. Added count method, which counts the
15
+ number of the specified elements in the HTMLDoc. Removed bug in remove_element.
16
16
  email: slmnwise@gmail.com
17
17
  executables: []
18
18
  extensions: []