android_string_resources_validator 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d59bc83f942aee4719a1fb7759933474ff8520f9
4
- data.tar.gz: 3067cf6c925a63c0b84a76de598b7d6f2b2bd083
3
+ metadata.gz: bb33197c711f35efcbda45b9f63accdda01bb62d
4
+ data.tar.gz: 75b84c69a50c06c181382c47d42e7296d16e89e8
5
5
  SHA512:
6
- metadata.gz: 3ef20a5ab64d8a12ce49ae170a83c5612fa2144688324a782bd583ef0b5d3b3f3b9ff20e844ba942983a6842cebdf0e08f71e3853a19f9f9bf483719848a6e6c
7
- data.tar.gz: 96f1bbe43aa23a8911e9ab89ab6c2433030593554643c8a743df36b42ee758cf7acd7985b4a1c9345ecdc02fffa758997d4f1b86ba104142381190bb6e7223f9
6
+ metadata.gz: c56cfb3ebc3551d4a47862ce49be1b7d40c795f9b41705f4b2715c68396827694504e21e57a24e8999a2dfd3c6037c4dc623daff47a9d637e596d17c54b37712
7
+ data.tar.gz: 356a1214ad133906edf45c11e67c9f88da57f73217b7d178f35182f816ea8a3472e09d09fd7a8bd104006189644faa55e243da21bfdd60f87c8f77d7c9b7a4e9
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # AndroidStringResourcesValidator
2
2
 
3
- [![Circle CI](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce)](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce)
3
+ [![Circle CI](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce)](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce) [![Code Climate](https://codeclimate.com/github/magplus/android_string_resources_validator.png)](https://codeclimate.com/github/magplus/android_string_resources_validator) ![Gem version](https://badge.fury.io/rb/android_string_resources_validator.png)
4
+
4
5
 
5
6
  Validates an Android strings.xml resource file against the specification at
6
7
  http://developer.android.com/guide/topics/resources/string-resource.html
@@ -2,8 +2,8 @@ require "android_string_resources_validator/version"
2
2
  require 'nokogiri'
3
3
 
4
4
  class AndroidStringResourcesValidator
5
- def initialize(string)
6
- @string = string
5
+ def initialize(xml)
6
+ @xml = xml
7
7
  end
8
8
 
9
9
  def valid?
@@ -11,21 +11,29 @@ class AndroidStringResourcesValidator
11
11
  end
12
12
 
13
13
  def errors
14
- strings.map(&:error).compact
14
+ (strings.map(&:error) << xml_error << document_type_error).compact
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  attr_reader :string
20
20
 
21
+ def xml_error
22
+ "Not a valid XML document" unless doc.errors.empty?
23
+ end
24
+
25
+ def document_type_error
26
+ "Not a string resource document" unless doc.xpath('/resources').length == 1
27
+ end
28
+
21
29
  def strings
22
- doc.xpath('//resources/string').map do |element|
30
+ doc.xpath('/resources/string').map do |element|
23
31
  ElementString.new(element.text)
24
32
  end
25
33
  end
26
34
 
27
35
  def doc
28
- Nokogiri::XML(@string)
36
+ Nokogiri::XML(@xml)
29
37
  end
30
38
 
31
39
  class ElementString
@@ -1,3 +1,3 @@
1
1
  class AndroidStringResourcesValidator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -37,6 +37,20 @@ describe AndroidStringResourcesValidator do
37
37
  assert_valid %q{Special identifiers such as %&amp; and %d are allowed}
38
38
  end
39
39
 
40
+ specify "Requires valid XML" do
41
+ invalid_xml = strings_xml('whatever').chop
42
+ validator = AndroidStringResourcesValidator.new(invalid_xml)
43
+ validator.errors.should == ["Not a valid XML document"]
44
+ validator.should_not be_valid
45
+ end
46
+
47
+ specify "Requires a string resources document" do
48
+ unknown_xml = %q{<foo><string name="ciao">I have no idea what XML this is!<resources>Who knows?</resources></string></foo>}
49
+ validator = AndroidStringResourcesValidator.new(unknown_xml)
50
+ validator.errors.should == ["Not a string resource document"]
51
+ validator.should_not be_valid
52
+ end
53
+
40
54
  private
41
55
 
42
56
  def strings_xml(string)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: android_string_resources_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Eklund