bmf-dialog 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +12 -0
- data/Rakefile +2 -0
- data/bin/bmf-dialog +16 -0
- data/bmf-dialog.gemspec +21 -0
- data/lib/bmf-dialog.rb +15 -0
- data/lib/bmf-dialog/parser.rb +37 -0
- data/lib/bmf-dialog/parser/dialog_parser.rb +22 -0
- data/lib/bmf-dialog/parser/line.rb +9 -0
- data/lib/bmf-dialog/version.rb +5 -0
- data/spec/bmf-dialog/parser_spec.rb +98 -0
- data/spec/bmf-dialog_spec.rb +30 -0
- data/spec/fixtures/dialog1.txt +10 -0
- data/spec/spec_helper.rb +21 -0
- metadata +89 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Klaas Speller
|
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
data/Rakefile
ADDED
data/bin/bmf-dialog
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# encoding: UTF-8
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
require 'bmf-dialog'
|
8
|
+
|
9
|
+
dialog_path = ARGV[0]
|
10
|
+
plist_path = ARGV[1]
|
11
|
+
|
12
|
+
$stdout.write result = Bmf::Dialog.parse(dialog_path)
|
13
|
+
|
14
|
+
if plist_path
|
15
|
+
File.open(plist_path, "w+") { |file| file.write result }
|
16
|
+
end
|
data/bmf-dialog.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bmf-dialog/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Klaas Speller"]
|
6
|
+
gem.email = ["klaas@le.mu.rs"]
|
7
|
+
gem.description = %q{Generate dialog plist}
|
8
|
+
gem.summary = %q{Generate dialog plist}
|
9
|
+
gem.homepage = "http://github.com/spllr/bmf-dialog"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "bmf-dialog"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bmf::Dialog::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'plist', "~> 3.1.0"
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
data/lib/bmf-dialog.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bmf-dialog/version"
|
2
|
+
require "bmf-dialog/parser"
|
3
|
+
|
4
|
+
module Bmf
|
5
|
+
module Dialog
|
6
|
+
class << self
|
7
|
+
def parse(data_or_path)
|
8
|
+
data_or_path = File.open(data_or_path, "r") if File.exists?(data_or_path)
|
9
|
+
data_or_path = data_or_path.read if data_or_path.respond_to?(:read)
|
10
|
+
|
11
|
+
Parser.new(data_or_path).parse.to_plist
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "plist"
|
2
|
+
require File.expand_path("../parser/dialog_parser.rb", __FILE__)
|
3
|
+
require File.expand_path("../parser/line.rb", __FILE__)
|
4
|
+
|
5
|
+
module Bmf
|
6
|
+
module Dialog
|
7
|
+
class Parser
|
8
|
+
attr_reader :dialog, :sections
|
9
|
+
|
10
|
+
def initialize(dialog)
|
11
|
+
@dialog = dialog
|
12
|
+
@sections = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse
|
16
|
+
dialog.split(/-+>/).each do |section|
|
17
|
+
next if section.strip.empty?
|
18
|
+
|
19
|
+
key = section.lines.first.strip
|
20
|
+
dialog_parser = DialogParser.new(section)
|
21
|
+
dialog_parser.parse
|
22
|
+
|
23
|
+
@sections[key] = dialog_parser
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
Hash[@sections.map { |k,v| [k, v.to_a] }]
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_plist
|
33
|
+
to_hash.to_plist
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Bmf
|
2
|
+
module Dialog
|
3
|
+
class DialogParser
|
4
|
+
|
5
|
+
attr_reader :dialog, :lines
|
6
|
+
def initialize(dialog)
|
7
|
+
@dialog = dialog
|
8
|
+
@lines = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
@dialog.scan(/^(.*?): (.*?)$/) do |m|
|
13
|
+
@lines << Line.new(*m)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
@lines.map(&:to_hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "bmf-dialog/parser"
|
4
|
+
|
5
|
+
|
6
|
+
describe Bmf::Dialog::Parser do
|
7
|
+
let(:dialog) { File.read(__FILE__).split('__END__').last }
|
8
|
+
let(:parser) { Bmf::Dialog::Parser.new(dialog) }
|
9
|
+
|
10
|
+
describe "parsing a dialog" do
|
11
|
+
before { parser.parse }
|
12
|
+
|
13
|
+
it 'finds all sections' do
|
14
|
+
parser.should have(2).sections
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'uses the correct names for the sections' do
|
18
|
+
parser.sections['First Dialog'].should_not be_nil
|
19
|
+
parser.sections['Second Dialog'].should_not be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "a dialog" do
|
24
|
+
before { parser.parse }
|
25
|
+
|
26
|
+
let(:dialog1) { parser.sections['First Dialog'] }
|
27
|
+
let(:dialog2) { parser.sections['Second Dialog'] }
|
28
|
+
|
29
|
+
it 'has the correct number of lines' do
|
30
|
+
dialog1.should have(3).lines
|
31
|
+
dialog2.should have(2).lines
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has the correct messages in the correct order' do
|
35
|
+
dialog1.lines[0].message.should == "Hello World!"
|
36
|
+
dialog1.lines[1].message.should == "Foobar dude"
|
37
|
+
dialog1.lines[2].message.should == "Say what?"
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has the correct speakers in the correct order' do
|
41
|
+
dialog1.lines[0].speaker.should == "Emma"
|
42
|
+
dialog1.lines[1].speaker.should == "Johnny"
|
43
|
+
dialog1.lines[2].speaker.should == "Emma"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#to_hash" do
|
48
|
+
before { parser.parse }
|
49
|
+
|
50
|
+
let(:hash) { parser.to_hash }
|
51
|
+
|
52
|
+
it 'returns a hash' do
|
53
|
+
hash.should be_a Hash
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns a hash with the dialog keys on root' do
|
57
|
+
hash['First Dialog'].should_not be_nil
|
58
|
+
hash['Second Dialog'].should_not be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'stores the lines as an array under the dialogs' do
|
62
|
+
hash['First Dialog'].should be_an Array
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'stores the lines data as a hash in the lines array' do
|
66
|
+
hash['First Dialog'][0].should be_a Hash
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#to_plist" do
|
71
|
+
before { parser.parse }
|
72
|
+
|
73
|
+
it 'can be called' do
|
74
|
+
parser.should respond_to :to_plist
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has the correct structure' do
|
78
|
+
restored = Plist.parse_xml parser.to_plist
|
79
|
+
|
80
|
+
restored['Second Dialog'][1]["message"].should == 'Yes it is'
|
81
|
+
restored['Second Dialog'][1]["speaker"].should == 'Mike'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
__END__
|
88
|
+
|
89
|
+
--> First Dialog
|
90
|
+
Emma: Hello World!
|
91
|
+
Johnny: Foobar dude
|
92
|
+
Emma: Say what?
|
93
|
+
|
94
|
+
-> Second Dialog
|
95
|
+
Sarha: Boy what day
|
96
|
+
Mike: Yes it is
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "bmf-dialog"
|
4
|
+
require "plist"
|
5
|
+
|
6
|
+
describe Bmf::Dialog do
|
7
|
+
specify 'parsing a dialog file from string' do
|
8
|
+
dialog = Bmf::Dialog.parse load_fixture('dialog1.txt')
|
9
|
+
|
10
|
+
Plist.parse_xml(dialog).should be_a Hash
|
11
|
+
Plist.parse_xml(dialog).should have(2).keys
|
12
|
+
Plist.parse_xml(dialog)['First Dialog'].size.should == 3
|
13
|
+
end
|
14
|
+
|
15
|
+
specify 'parsing a dialog file from a file object' do
|
16
|
+
dialog = Bmf::Dialog.parse load_fixture_file('dialog1.txt')
|
17
|
+
|
18
|
+
Plist.parse_xml(dialog).should be_a Hash
|
19
|
+
Plist.parse_xml(dialog).should have(2).keys
|
20
|
+
Plist.parse_xml(dialog)['First Dialog'].size.should == 3
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'parsing a dialog file from a file path' do
|
24
|
+
dialog = Bmf::Dialog.parse fixture_path('dialog1.txt')
|
25
|
+
|
26
|
+
Plist.parse_xml(dialog).should be_a Hash
|
27
|
+
Plist.parse_xml(dialog).should have(2).keys
|
28
|
+
Plist.parse_xml(dialog)['First Dialog'].size.should == 3
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
2
|
+
RSpec.configure do |config|
|
3
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
4
|
+
config.run_all_when_everything_filtered = true
|
5
|
+
config.filter_run :focus
|
6
|
+
|
7
|
+
config.order = 'random'
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def fixture_path(name)
|
12
|
+
File.expand_path(File.join('../fixtures', name), __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_fixture_file(name)
|
16
|
+
File.open fixture_path(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_fixture(name)
|
20
|
+
load_fixture_file(name).read
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bmf-dialog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Klaas Speller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: plist
|
16
|
+
requirement: &70168784313260 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70168784313260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70168784312840 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70168784312840
|
36
|
+
description: Generate dialog plist
|
37
|
+
email:
|
38
|
+
- klaas@le.mu.rs
|
39
|
+
executables:
|
40
|
+
- bmf-dialog
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/bmf-dialog
|
51
|
+
- bmf-dialog.gemspec
|
52
|
+
- lib/bmf-dialog.rb
|
53
|
+
- lib/bmf-dialog/parser.rb
|
54
|
+
- lib/bmf-dialog/parser/dialog_parser.rb
|
55
|
+
- lib/bmf-dialog/parser/line.rb
|
56
|
+
- lib/bmf-dialog/version.rb
|
57
|
+
- spec/bmf-dialog/parser_spec.rb
|
58
|
+
- spec/bmf-dialog_spec.rb
|
59
|
+
- spec/fixtures/dialog1.txt
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: http://github.com/spllr/bmf-dialog
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Generate dialog plist
|
85
|
+
test_files:
|
86
|
+
- spec/bmf-dialog/parser_spec.rb
|
87
|
+
- spec/bmf-dialog_spec.rb
|
88
|
+
- spec/fixtures/dialog1.txt
|
89
|
+
- spec/spec_helper.rb
|