apstrings 0.2.1 → 0.2.2

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: a2654ba9a832170ed36762b56735ed6ba7c07e19
4
- data.tar.gz: ba194e889adfdcb6217d84a8f3a7d06f320d83a1
3
+ metadata.gz: e34ce4ce8368783b9945b8b89844ff9f2d88e66a
4
+ data.tar.gz: 2f61172036204cbd1802e983bd15e819bb118480
5
5
  SHA512:
6
- metadata.gz: 6d284ad330632b177317620c1c7092bffe8ac1d84cc93e525eb59eef60c418f41b682b4138167a4bd6f5dc1b2df3413025a79dcddc8643712ae56e7bf2bd56d0
7
- data.tar.gz: 71d4d1c27185dc11491677be60b01af6dad88e5da87edba3767dbb0ae615554162d74f2b54559940915be746b487e1aa9ebfed27335dcaa10f803e4f1565464d
6
+ metadata.gz: ea3c22a1ccef37b8074f9a0d7a08de3213c02910464bdca746d1f78d047d2ced13b396d49920d71ddcf3371f76be266f4c6355718033ddb8346e77f298546317
7
+ data.tar.gz: c97ceb1f97eb388e19be1488abb122118f597b929ad6f10c973f2727db54f12b5a7d1dc118e2e9f23330adfa22ec5b3875f98c0aa358cd55bc848d6fe1c1ac79
Binary file
data/bin/apstrings ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apstrings"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+
14
+ $ROOT = ARGV[0]
15
+
16
+ Dir::chdir($ROOT)
17
+ files_to_validate = {"master"=> nil,"files" => []}
18
+ Dir.glob(File.join("**", "*.bundle","**","*.strings")) { |file|
19
+ p File.basename(file)
20
+ if File.basename(file) == "zh-Hans.strings"
21
+ files_to_validate["master"] = File.expand_path(file)
22
+ else
23
+ files_to_validate["files"] << File.expand_path(file)
24
+ end
25
+ }
26
+
27
+ success = true
28
+ files_to_validate["files"].each { |file|
29
+ if !Apstrings::validate(file,files_to_validate["master"])
30
+ success = false
31
+ end
32
+ }
33
+
34
+ p success ? "Success, well done!" : "Failed: You'd better know what r u doing..."
35
+
36
+
37
+
38
+
data/bin/setup CHANGED
@@ -4,4 +4,4 @@ IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
6
 
7
- # Do any other automated setup that you need to do here
7
+ # Do any other automated setup that you need to do here
@@ -6,9 +6,12 @@ module Apstrings
6
6
  class Validator
7
7
 
8
8
  def self.validate(file,masterFile)
9
+ @master = nil
9
10
  puts "apstrings: start validate strings file ..."
10
11
  if nil == masterFile
11
12
  Log::warn("No master file provided, validating file format for #{file} only ...")
13
+ else
14
+ @master = Validator::paredFile(masterFile)
12
15
  end
13
16
 
14
17
  valid_master, valid_file , no_missing_key = true,true,true
@@ -82,9 +85,10 @@ module Apstrings
82
85
  mismatchs = []
83
86
  sf.key_values.each {
84
87
  |e| e.each_pair {
85
- |key,value|
88
+ |key,value|
89
+ fixed_key = Validator::value_in_master(key)
86
90
  striped_value = value.gsub(/%\d\$/,'%') # Strip numbered format placeholders , e.g. %1$@ --> %@
87
- key_variables = key.scan(variables_regex)
91
+ key_variables = fixed_key.scan(variables_regex)
88
92
  value_variables = striped_value.scan(variables_regex)
89
93
  if !(key_variables.sort == value_variables.sort)
90
94
  mismatchs << {key => value}
@@ -99,6 +103,19 @@ module Apstrings
99
103
  StringsParser.new(file).parse_file
100
104
  end
101
105
 
106
+ def self.value_in_master(key)
107
+ if @master
108
+ value_comment = @master.to_hash[key] #
109
+ if value_comment == nil
110
+ return key
111
+ else
112
+ return value_comment.keys[0]
113
+ end
114
+ else
115
+ key
116
+ end
117
+ end
118
+
102
119
  end
103
120
 
104
121
  end
@@ -0,0 +1,27 @@
1
+
2
+ require 'apstrings'
3
+
4
+
5
+
6
+ $ROOT = ARGV[0]
7
+
8
+ Dir::chdir($ROOT)
9
+ files_to_validate = {"master"=> nil,"files" => []}
10
+ Dir.glob(File.join("**", "*.bundle","**","*.strings")) { |file|
11
+ p File.basename(file)
12
+ if File.basename(file) == "zh-Hans.strings"
13
+ files_to_validate["master"] = File.expand_path(file)
14
+ else
15
+ files_to_validate["files"] << File.expand_path(file)
16
+ end
17
+ }
18
+
19
+ success = true
20
+ files_to_validate["files"].each { |file|
21
+ # p files_to_validate["master"].to_hash[""]
22
+ if !Apstrings::validate(file,files_to_validate["master"])
23
+ success = false
24
+ end
25
+ }
26
+
27
+ p success ? "Success, well done!" : "Failed: You'd better know what r u doing..."
@@ -1,3 +1,3 @@
1
1
  module Apstrings
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apstrings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JasonWorking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-29 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,6 +56,7 @@ description: An easy to use Apple dot strings file parser with encoding handled.
56
56
  email:
57
57
  - 331314708@qq.com
58
58
  executables:
59
+ - apstrings
59
60
  - console
60
61
  - setup
61
62
  extensions: []
@@ -68,7 +69,9 @@ files:
68
69
  - LICENSE.txt
69
70
  - README.md
70
71
  - Rakefile
72
+ - apstrings-0.2.1.gem
71
73
  - apstrings.gemspec
74
+ - bin/apstrings
72
75
  - bin/console
73
76
  - bin/setup
74
77
  - lib/apstrings.rb
@@ -79,6 +82,7 @@ files:
79
82
  - lib/apstrings/reader.rb
80
83
  - lib/apstrings/strings_parser.rb
81
84
  - lib/apstrings/strings_validator.rb
85
+ - lib/apstrings/tester.rb
82
86
  - lib/apstrings/version.rb
83
87
  homepage: https://github.com/JasonWorking
84
88
  licenses: