kowabana-parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11f97b601cdb9981e8744eb39528108292e9f206
4
+ data.tar.gz: 2f5cfbff7cf0ee020294ae966b2eeb32524d5548
5
+ SHA512:
6
+ metadata.gz: 71d890890c6e22ccaeb724e28c8140eed18b20b6ff1256c393df05f80af702615e3478adf75e548f9bd1f99fe230ec905439c1316e34865db7cb171418c7ef23
7
+ data.tar.gz: 337d17e7419fbb8e30698a6c10c42ea458c88e327f578f2cc4c59dc26c776090e65deda488e702bee455f88d87b2c5d482dc030a988777c273e505a9e8a90293
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - jruby-1.7.12
7
+ - rbx-2.2.7
8
+ - ruby-head
9
+ - jruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+ - rvm: jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kowabana-parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masaki Komagata
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # kowabana-parser
2
+
3
+ ![TravisCI Build Status](https://secure.travis-ci.org/fjordllc/kowabana-parser.png)
4
+
5
+ Parsing KML(Kowabana Markup Language).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kowabana-parser'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kowabana-parser
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ parser = Kowabana::Parser.new(<<-EOS)
27
+ music:1
28
+ aaaaaaaaaaaa
29
+ wallpaper:1
30
+ music:3
31
+ shake
32
+
33
+ wallpaper:2
34
+ sound:1
35
+ nextpage
36
+
37
+ wallpaper:4
38
+ bbbbbbbbbbbb
39
+ sound:3
40
+ EOS
41
+
42
+ parser.wallpaper_ids #=> [1, 2, 4]
43
+ parser.music_ids #=> [1, 3]
44
+ parser.sound_ids #=> [1, 3]
45
+ parser.plain_texts #=> ['aaaaaaaaaaaa', 'bbbbbbbbbbbb']
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/kowabana-parser/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/test_*.rb'
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kowabana/parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kowabana-parser'
8
+ spec.version = Kowabana::Parser::VERSION
9
+ spec.authors = ['Masaki Komagata']
10
+ spec.email = ['komagata@gmail.com']
11
+ spec.summary = 'Parsing KML(Kowabana Markup Language).'
12
+ spec.description = 'Parsing KML(Kowabana Markup Language).'
13
+ spec.homepage = 'https://github.com/fjordllc/kowabana-parser'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'test-unit', '~> 3.0.8'
24
+ spec.add_development_dependency 'pry-byebug', '~> 2.0.0'
25
+ end
@@ -0,0 +1,43 @@
1
+ require 'kowabana/parser/version'
2
+
3
+ module Kowabana
4
+ class Parser
5
+ attr_accessor :text, :texts, :plain_texts
6
+ attr_reader :wallpaper_ids, :music_ids, :sound_ids
7
+
8
+ def initialize(text = '')
9
+ @text = text
10
+ @plain_texts = []
11
+ @wallpaper_ids = []
12
+ @music_ids = []
13
+ @sound_ids = []
14
+ end
15
+
16
+ def parse!
17
+ cleanup!
18
+ @texts.each do |line|
19
+ case line
20
+ when /^wallpaper:\d+$/
21
+ @wallpaper_ids << line.split(':').last.to_i
22
+ when /^music:\d+$/
23
+ @music_ids << line.split(':').last.to_i
24
+ when /^sound:\d+$/
25
+ @sound_ids << line.split(':').last.to_i
26
+ when /^shake$/
27
+ # do nothing
28
+ when /^nextpage$/
29
+ # do nothing
30
+ else
31
+ @plain_texts << line
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def cleanup!
39
+ @text = @text.gsub(/(\r\n|\r)/, "\n").gsub(/\n+/, "\n")
40
+ @texts = @text.split("\n").map(&:strip)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Kowabana
2
+ class Parser
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require_relative '../lib/kowabana/parser'
4
+ require 'pry-byebug'
5
+
6
+ class TestKowabanaParser < Test::Unit::TestCase
7
+ def setup
8
+ @parser = Kowabana::Parser.new
9
+ end
10
+
11
+ def test_parse!
12
+ @parser.text = <<-EOS
13
+ aaaaaaaaaaaa
14
+ bbbbbbbbbbbb
15
+
16
+ cccccccccccc
17
+
18
+
19
+ dddddddddddd
20
+ EOS
21
+ @parser.parse!
22
+ assert { [] == @parser.wallpaper_ids }
23
+ assert { [] == @parser.music_ids }
24
+ assert { [] == @parser.sound_ids }
25
+ plain = [
26
+ 'aaaaaaaaaaaa',
27
+ 'bbbbbbbbbbbb',
28
+ 'cccccccccccc',
29
+ 'dddddddddddd'
30
+ ]
31
+ assert { plain == @parser.plain_texts }
32
+ end
33
+
34
+ def test_command_parse!
35
+ @parser.text = <<-EOS2
36
+ music:1
37
+ aaaaaaaaaaaa
38
+ wallpaper:1
39
+ music:3
40
+ shake
41
+ wallpaper:2
42
+ sound:1
43
+ nextpage
44
+
45
+ wallpaper:4
46
+ bbbbbbbbbbbb
47
+ sound:3
48
+ EOS2
49
+ @parser.parse!
50
+ assert { [1, 2, 4] == @parser.wallpaper_ids }
51
+ assert { [1, 3] == @parser.music_ids }
52
+ assert { [1, 3] == @parser.sound_ids }
53
+ plain = [
54
+ 'aaaaaaaaaaaa',
55
+ 'bbbbbbbbbbbb'
56
+ ]
57
+ assert { plain == @parser.plain_texts }
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kowabana-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masaki Komagata
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 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
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ description: Parsing KML(Kowabana Markup Language).
70
+ email:
71
+ - komagata@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - kowabana-parser.gemspec
83
+ - lib/kowabana/parser.rb
84
+ - lib/kowabana/parser/version.rb
85
+ - test/test_kowabana_parser.rb
86
+ homepage: https://github.com/fjordllc/kowabana-parser
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Parsing KML(Kowabana Markup Language).
110
+ test_files:
111
+ - test/test_kowabana_parser.rb