lang-script 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lang-script.rb +80 -0
  3. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0ddc5c2d3b01aaa1ede5fb7b843cf1de127a2d5
4
+ data.tar.gz: ed1e62fa8304685f6e57bdc21b1b78b360a18b5e
5
+ SHA512:
6
+ metadata.gz: aa0163836c759b366fcc9ba0c4f5fa6623f098ab27d77153b07ef8584e73fdf3a446b255cc5dd4f634aff5ca87032fe6d02932e6e4dcafb67b6af1cad26a8292
7
+ data.tar.gz: 14320e584e5e8c906e228b181b6292a4d3e5c7ba345718393e5284d307e85c3c5eb74cb445d874f64557379f7d837573d4a9c65e2bf32ad927c83bfe47212221
data/lang-script.rb ADDED
@@ -0,0 +1,80 @@
1
+ module LANGScript
2
+ MAJOR = 0x01
3
+ MINOR = 0x01
4
+
5
+ TAG_BEGIN = [0xC2,140].pack('C*')
6
+ TAG_NAME = [0xC2,150].pack('C*')
7
+ TAG_TEXT = [0xC2,160].pack('C*')
8
+ TAG_LINE = [0xC2,170].pack('C*')
9
+ LNG_BEGIN = [0xC2,180].pack('C*')
10
+ LNG_TAGS = [0xC2,190].pack('C*')
11
+ LNG_END = [0xC3,136].pack('C*')
12
+
13
+ #----------------------------------------------------------------------------
14
+ # * Carregamento dos arquivos de linguagem
15
+ #----------------------------------------------------------------------------
16
+ def load_files
17
+ Dir.entries(FOLDER).each do |entry|
18
+ next unless FileTest.file?(FOLDER + '/' + entry)
19
+ txt = File.open(FOLDER + '/' + entry, 'rb') {|f| f.read}
20
+ major = txt[0].unpack('U').first
21
+ minor = txt[1].unpack('U').first
22
+
23
+ if major > MAJOR || (major >= MAJOR && minor > MINOR)
24
+ puts "LANG Script version not compatible"
25
+ return ''
26
+ end
27
+
28
+ enc = txt[2].unpack('U').first > 1
29
+ txt = txt[3..-1]
30
+ txt.split(LNG_END).each do |l|
31
+ langname = enc ? decrypt(l[LNG_BEGIN.size...l.index(LNG_TAGS)]) : l[LNG_BEGIN.size...l.index(LNG_TAGS)]
32
+ unless l[0...LNG_BEGIN.size] == LNG_BEGIN
33
+ puts "Invalid language file"
34
+ return ''
35
+ end
36
+ l[(l.index(LNG_TAGS) + LNG_TAGS.size)..-1].split("\n").each do |t|
37
+ unless t[0...TAG_BEGIN.size] == TAG_BEGIN
38
+ puts "Invalid language file"
39
+ return ''
40
+ end
41
+ unless t[TAG_BEGIN.size..(TAG_NAME.size+1)] == TAG_NAME
42
+ puts "Invalid language file"
43
+ return ''
44
+ end
45
+ i = t.index(TAG_TEXT)
46
+ unless i
47
+ puts "Invalid language file"
48
+ return ''
49
+ end
50
+ name = enc ? decrypt(t[(TAG_BEGIN.size + TAG_NAME.size)...i]) : t[(TAG_BEGIN.size + TAG_NAME.size)...i].force_encoding('UTF-8')
51
+ text = enc ? decrypt(t[(i+TAG_TEXT.size)...t.size]) : t[(i+TAG_TEXT.size)...t.size].force_encoding('UTF-8')
52
+ begin
53
+ LANGUAGES[langname] ||= {}
54
+ LANGUAGES[langname][name] = text.gsub(TAG_LINE.force_encoding('UTF-8'), "\n")
55
+ rescue
56
+ puts "Invalid language file"
57
+ return ''
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ #----------------------------------------------------------------------------
65
+ # * Carregamento de uma string
66
+ #----------------------------------------------------------------------------
67
+ def load(tag, lang)
68
+ load_files unless LANGUAGES.keys.include? lang
69
+ if LANGUAGES[lang]
70
+ if LANGUAGES[lang][tag]
71
+ return LANGUAGES[lang][tag]
72
+ else
73
+ puts "Failed to load tag '#{tag}': Could not find tag"
74
+ end
75
+ else
76
+ puts "Failed to load tag '#{tag}': Could not find language"
77
+ end
78
+ return ''
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lang-script
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Masked
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A module with methods for reading LANG Script .language files
42
+ email:
43
+ - masked.rpg@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - "./lang-script.rb"
49
+ homepage: ''
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: LANG Script reader
73
+ test_files: []