Class: AndroidStringResourcesValidator::ElementString
- Inherits:
-
Object
- Object
- AndroidStringResourcesValidator::ElementString
- Defined in:
- lib/android_string_resources_validator.rb
Instance Method Summary collapse
- #contains_unescaped_double_quotes ⇒ Object
- #contains_unescaped_single_quotes ⇒ Object
- #error ⇒ Object
-
#initialize(string) ⇒ ElementString
constructor
A new instance of ElementString.
- #string_without_double_quotes_contains_unescaped_double_quotes ⇒ Object
- #string_without_single_quotes_contains_unescaped_single_quotes ⇒ Object
- #surrounded_by_double_quotes ⇒ Object
- #surrounded_by_single_quotes ⇒ Object
- #unsurrounded_contains_unescaped_double_quotes ⇒ Object
- #unsurrounded_contains_unescaped_single_quotes ⇒ Object
Constructor Details
#initialize(string) ⇒ ElementString
40 41 42 |
# File 'lib/android_string_resources_validator.rb', line 40 def initialize(string) @string = string end |
Instance Method Details
#contains_unescaped_double_quotes ⇒ Object
71 72 73 |
# File 'lib/android_string_resources_validator.rb', line 71 def contains_unescaped_double_quotes @string[/[^\\]"/] end |
#contains_unescaped_single_quotes ⇒ Object
63 64 65 |
# File 'lib/android_string_resources_validator.rb', line 63 def contains_unescaped_single_quotes @string[/[^\\]'/] end |
#error ⇒ Object
44 45 46 47 48 49 |
# File 'lib/android_string_resources_validator.rb', line 44 def error return "Apostrophes must be escaped" if unsurrounded_contains_unescaped_single_quotes return "Double quotes must be escaped" if unsurrounded_contains_unescaped_double_quotes return "Double quotes must be escaped or surrounded by single quotes" if string_without_double_quotes_contains_unescaped_double_quotes return "Single quotes must be escaped or surrounded by double quotes" if string_without_single_quotes_contains_unescaped_single_quotes end |
#string_without_double_quotes_contains_unescaped_double_quotes ⇒ Object
79 80 81 |
# File 'lib/android_string_resources_validator.rb', line 79 def string_without_double_quotes_contains_unescaped_double_quotes @string[/\A".*[^\\]".*"\z/] end |
#string_without_single_quotes_contains_unescaped_single_quotes ⇒ Object
75 76 77 |
# File 'lib/android_string_resources_validator.rb', line 75 def string_without_single_quotes_contains_unescaped_single_quotes @string[/\A'.*[^\\]'.*'\z/] end |
#surrounded_by_double_quotes ⇒ Object
59 60 61 |
# File 'lib/android_string_resources_validator.rb', line 59 def surrounded_by_double_quotes @string[/\A".*"\z/] end |
#surrounded_by_single_quotes ⇒ Object
67 68 69 |
# File 'lib/android_string_resources_validator.rb', line 67 def surrounded_by_single_quotes @string[/\A'.*'\z/] end |
#unsurrounded_contains_unescaped_double_quotes ⇒ Object
55 56 57 |
# File 'lib/android_string_resources_validator.rb', line 55 def unsurrounded_contains_unescaped_double_quotes !surrounded_by_double_quotes && !surrounded_by_single_quotes && contains_unescaped_double_quotes end |
#unsurrounded_contains_unescaped_single_quotes ⇒ Object
51 52 53 |
# File 'lib/android_string_resources_validator.rb', line 51 def unsurrounded_contains_unescaped_single_quotes !surrounded_by_double_quotes && !surrounded_by_single_quotes && contains_unescaped_single_quotes end |