code_terminator 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25941d00626fb70ed84292b3cc0ab04b43210705
4
- data.tar.gz: a2b84902e9de3783173141d6df9e07977469fa1e
3
+ metadata.gz: 87e6dca14dbac0d4b60af01602c73f19d2155cb1
4
+ data.tar.gz: 690cd6aa18eeca2de64d86d5aadff6a081b87086
5
5
  SHA512:
6
- metadata.gz: b3f5462fda6d99fc756772324786f688675c571ffdefed1642f4dabd4ea14b16cee7924e15e8e636a7c3d6df6e638db1c74df6f94568dc65b53e7365a235da84
7
- data.tar.gz: d7f0ea3dddb4c2e8ada76dafb5e1ee2861022b48b8b1f6fa3d95f491a3f9fa228669f908746a923d9af4d14f335f1d6e90457856b0df25e847a9b0d41908fc4a
6
+ metadata.gz: 08c93b876778cd097b3de362176f257a3870e1991ad9f2eb73551c8f4d30ddeecef52b1504f6010d9204febaa2fd33896953f68dbabb2fcde299203b7d0f6825
7
+ data.tar.gz: 11e944f39c5fd1fab19654fd4ad60289840662c4386d50e39e0b92bd117328b7b0ccdc8d8dc366d18b2fb321f438bbfd68b81b8e36d6524325de022846668b86
data/README.md CHANGED
@@ -154,7 +154,7 @@ Validate if the syntax is correct. Return an array with errors.
154
154
  ```
155
155
 
156
156
  ###get_elements(source)
157
- Get html elements of a html file. Return a list of Nokogiri XML objects.
157
+ Get html elements of a html file. Return a list of elements with their properties.
158
158
  #####HTML
159
159
  ```ruby
160
160
  >> ct = CodeTerminator::Html.new
@@ -168,19 +168,33 @@ Get html elements of a html file. Return a list of Nokogiri XML objects.
168
168
  # => [{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}]
169
169
  ```
170
170
 
171
- ###print_elements(Elements Array)
171
+ ###get_instructions(source)
172
+ Get the instructions to recreate the html code. Return an array with strings .
173
+ #####HTML
174
+ ```ruby
175
+ >> ct = CodeTerminator::Html.new
176
+ >> ct.get_instructions("hola_mundo.html")
177
+ # => ["Add the tag h2 in body", " In h2 add the text 'hola test' ", "Add the tag p in body"]
178
+ ```
179
+ #####CSS
180
+ ```ruby
181
+ >> ct = CodeTerminator::Css.new
182
+ >> ct.get_instructions("hola_mundo.css")
183
+ # => ["Create the selector body", "In the selector body add the property ' background-color' with value 'yellow' "]
184
+ ```
185
+
186
+ ###print_elements(source)
172
187
  Get the elements of the code in html format. Return a string with elements in html.
173
188
  <br>
174
- **Get 'Elements Array' calling 'get_elements()'
175
189
  #####HTML
176
190
  ```ruby
177
- CodeTerminator::Html.print_elements(=> [{:parent=>"body", :tag=>"div", :attribute=>"class", :value=>"col-md-12"}, {:parent=>"div", :tag=>"h1"}, {:parent=>"h1", :tag=>"text", :content=>"Come with me if you want to live!"}] )
191
+ CodeTerminator::Html.print_elements("exercises/hola_mundo.html" )
178
192
  # => "name = h1<br><hr>name = text<br>content = Come with me if you want to live!<br><hr>"
179
193
  #
180
194
  ```
181
195
  #####CSS
182
196
  ```ruby
183
- CodeTerminator::Css.print_elements([{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}])
197
+ CodeTerminator::Css.print_elements("exercises/hola_mundo.css" )
184
198
  # => "selector = h1<br><hr>property = margin<br>value = 50px<br><hr>"
185
199
  #
186
200
  ```
@@ -134,7 +134,7 @@ class CodeTerminator::Css
134
134
  # Get the elements of the code in css format. Return a string with elements in css.
135
135
  #
136
136
  # Example:
137
- # >> CodeTerminator::Css.print_elements([{:selector=>"body"}, {:selector=>"body", :property=>"background-color", :value=>"lightblue"}] )
137
+ # >> CodeTerminator::Css.print_elements("exercises/hola_mundo.css" )
138
138
  # => "selector = body<br><hr>selector = body<br>property = background-color<br>value = lightblue<br><hr>"
139
139
  #
140
140
  # Arguments:
@@ -142,6 +142,7 @@ class CodeTerminator::Css
142
142
 
143
143
 
144
144
  def print_elements(elements)
145
+ elements = get_elements(source)
145
146
  text = ""
146
147
  elements.each do |child|
147
148
  text << "selector = " + child[:selector] + "<br>"
@@ -152,6 +153,33 @@ class CodeTerminator::Css
152
153
  text
153
154
  end
154
155
 
156
+ # Get the instructions to recreate the html code. Return an array with strings .
157
+ #
158
+ # Example:
159
+ # >> CodeTerminator::Css.get_instructions(file.get_elements("exercises/test.css"))
160
+ # => [["Create the selector body", "In the selector body add the property 'background-color' with value 'yellow' "]
161
+ #
162
+ # Arguments:
163
+ # instructions: (Array)
164
+
165
+ def get_instructions(source)
166
+ elements = get_elements(source)
167
+ text = ""
168
+ instructions = Array.new
169
+ elements.each do |child|
170
+ if child[:property].nil?
171
+ text << "Create the selector " + child[:selector]
172
+ else
173
+ text << "In the selector " + child[:selector] + " add the property '" + child[:property] + "'" if !child[:property].nil?
174
+ text << " with value '" + child[:value] + "' " if !child[:value].nil?
175
+ end
176
+ instructions.push(text)
177
+ text = ""
178
+ end
179
+ instructions
180
+ end
181
+
182
+
155
183
 
156
184
  # Match if the code have the same elements than the exercise. Return an array with the mismatches.
157
185
 
@@ -144,7 +144,7 @@ class CodeTerminator::Html
144
144
  # Get the elements of the code in html format. Return a string with elements in html.
145
145
  #
146
146
  # Example:
147
- # >> CodeTerminator::Html.print_elements([#<Nokogiri::XML::Element:0x3fe31dc42bfc name="h1" children=[#<Nokogiri::XML::Text:0x3fe31dc42b70 "hola mundo">]>, #<Nokogiri::XML::Text:0x3fe31dc42b70 "hola mundo">])
147
+ # >> CodeTerminator::Html.print_elements("exercises/hola_mundo.html" )
148
148
  # => "name = h1<br><hr>name = text<br>content = hola mundo<br><hr>"
149
149
  #
150
150
  # Arguments:
@@ -163,6 +163,35 @@ class CodeTerminator::Html
163
163
  text
164
164
  end
165
165
 
166
+ # Get the instructions to recreate the html code. Return an array with strings .
167
+ #
168
+ # Example:
169
+ # >> CodeTerminator::Html.get_instructions(file.get_elements("exercises/test.html"))
170
+ # => ["Add the tag h2 in body", "Add the tag text in h2 with content 'hola test' ", "Add the tag p in body"]
171
+ #
172
+ # Arguments:
173
+ # instructions: (Array)
174
+
175
+ def get_instructions(source)
176
+ elements = get_elements(source)
177
+ text = ""
178
+ instructions = Array.new
179
+ elements.each do |child|
180
+ if child[:tag]!="text"
181
+ text << "Add the tag " + child[:tag]
182
+ text << " in " + child[:parent] if !child[:parent].nil?
183
+ text << " with an attribute '" + child[:attribute] + "' " if !child[:attribute].nil?
184
+ text << " with value '" + child[:value] + "' " if !child[:value].nil?
185
+ else
186
+ text << " In " + child[:parent]+ " add the text '" + child[:content] + "' " if !child[:content].nil?
187
+ end
188
+ instructions.push(text)
189
+ text = ""
190
+ end
191
+ instructions
192
+ end
193
+
194
+
166
195
 
167
196
  # Match if the code have the same elements than the exercise. Return an array with the mismatches.
168
197
  #
@@ -1,3 +1,3 @@
1
1
  module CodeTerminator
2
- VERSION = "0.2.7"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_terminator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evelin Ponce