khayyam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 0.0.1 / 2008-12-20
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ features/export.feature
6
+ features/import.feature
7
+ features/steps/export_steps.rb
8
+ features/steps/import_steps.rb
9
+ lib/khayyam.rb
10
+ lib/topic.rb
11
+ spec/spec.opts
12
+ spec/spec_helper.rb
13
+ spec/topic_spec.rb
@@ -0,0 +1,107 @@
1
+ = khayyam
2
+
3
+ * http://khayyam.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ A gem for easily moving data and definititions, such as vocabulary words and definitions to and from files
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * See SYNOPSIS.
12
+
13
+ == SYNOPSIS:
14
+
15
+ Export data to a string
16
+
17
+ Example:
18
+ topic = Khayyam::Topic.new "vi"
19
+ topic.regarding "movement" do |items|
20
+ items["h"] = "left"
21
+ items["j"] = "up"
22
+ end
23
+ topic.regarding "commands" do |items|
24
+ items[":q"] = "quit"
25
+ items[":x"] = "save and quit"
26
+ end
27
+ output_string = topic.export
28
+
29
+
30
+ Import data from a string.
31
+
32
+ Example:
33
+ topic = Khayyam::Topic.import my_data
34
+ topic.regarding "foo" do |facts|
35
+ puts facts["bar"]
36
+ end
37
+
38
+ => "monkey"
39
+
40
+ == REQUIREMENTS:
41
+
42
+ * N/A
43
+
44
+ == INSTALL:
45
+
46
+ * sudo gem install khayyam
47
+
48
+ == LICENSE:
49
+
50
+ (The Ruby License)
51
+
52
+ Copyright (c) 2008 Jamal Hansen
53
+
54
+ Khayyam is copyrighted free software by Jamal Hansen
55
+ <jamal.hansen at gmail dot com> and contributors. You can redistribute it and/or
56
+ modify it under either the terms of the GPL2 or the conditions below:
57
+
58
+ 1. You may make and give away verbatim copies of the source form of the
59
+ software without restriction, provided that you duplicate all of the
60
+ original copyright notices and associated disclaimers.
61
+
62
+ 2. You may modify your copy of the software in any way, provided that
63
+ you do at least ONE of the following:
64
+
65
+ a) place your modifications in the Public Domain or otherwise make them
66
+ Freely Available, such as by posting said modifications to Usenet or an
67
+ equivalent medium, or by allowing the author to include your
68
+ modifications in the software.
69
+
70
+ b) use the modified software only within your corporation or
71
+ organization.
72
+
73
+ c) rename any non-standard executables so the names do not conflict with
74
+ standard executables, which must also be provided.
75
+
76
+ d) make other distribution arrangements with the author.
77
+
78
+ 3. You may distribute the software in object code or executable
79
+ form, provided that you do at least ONE of the following:
80
+
81
+ a) distribute the executables and library files of the software,
82
+ together with instructions (in the manual page or equivalent) on where
83
+ to get the original distribution.
84
+
85
+ b) accompany the distribution with the machine-readable source of the
86
+ software.
87
+
88
+ c) give non-standard executables non-standard names, with
89
+ instructions on where to get the original software distribution.
90
+
91
+ d) make other distribution arrangements with the author.
92
+
93
+ 4. You may modify and include the part of the software into any other
94
+ software (possibly commercial). But some files in the distribution
95
+ are not written by the author, so that they are not under this terms.
96
+
97
+ 5. The scripts and library files supplied as input to or produced as
98
+ output from the software do not automatically fall under the
99
+ copyright of the software, but belong to whomever generated them,
100
+ and may be sold commercially, and may be aggregated with this
101
+ software.
102
+
103
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
104
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
105
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
106
+ PURPOSE.
107
+
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+ require 'rubygems'
3
+ require 'hoe'
4
+ require 'cucumber/rake/task'
5
+ require './lib/khayyam.rb'
6
+
7
+ Hoe.new('khayyam', Khayyam::VERSION) do |p|
8
+ p.developer('Jamal Hansen', 'jamal.hansen@gmail.com')
9
+ p.changes=p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
+ end
11
+
12
+ Cucumber::Rake::Task.new
13
+
14
+ # vim: syntax=Ruby
@@ -0,0 +1,17 @@
1
+ Story: Exporting a single file
2
+ As a user of Khayyam
3
+ I want to export a file with khayyam
4
+ So that I can use the data elsewhere
5
+
6
+ Scenario: Export a file containing a single category
7
+ Given an object containing data to export
8
+ When I tell khayaam to export the file
9
+ Then it will export the file
10
+ And it will contain all the data in the original objects
11
+
12
+ Scenario: Export a file containing multiple categories
13
+ Given an object containing multiple categories to export
14
+ When I tell khayaam to export the file
15
+ Then it will export the file
16
+ And it will contain all the data and categories in the original objects
17
+
@@ -0,0 +1,11 @@
1
+ Story: Importing a string
2
+ As a user of Khayyam
3
+ I want to import a string with khayyam
4
+ So that I can use it with my application
5
+
6
+ Scenario: Import a string containing a single category
7
+ Given a string containing data to import
8
+ When I tell khayaam to import the string
9
+ Then it will import the string into khayyam
10
+ And it will contain all the data in the string
11
+
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. spec spec_helper.rb])
2
+
3
+ Given /^an object containing data to export$/ do
4
+ @topic = Khayyam::Topic.new "vi"
5
+ @topic.regarding "movement" do |items|
6
+ items["h"] = "left"
7
+ items["j"] = "up"
8
+ items["k"] = "down"
9
+ items["l"] = "right"
10
+ items["^"] = "beginning of line"
11
+ items["$"] = "end of line"
12
+ items["w"] = "beginning of next word"
13
+ end
14
+ end
15
+
16
+ When /^I tell khayaam to export the file$/ do
17
+ @output = @topic.export
18
+ end
19
+
20
+ Then /^it will export the file$/ do
21
+ @output.should_not eql(nil)
22
+ end
23
+
24
+ Then /^it will contain all the data in the original objects$/ do
25
+ @output.should eql("topic: vi\ncategories: \n movement: \n k: down\n w: beginning of next word\n l: right\n $: end of line\n ^: beginning of line\n h: left\n j: up\n")
26
+ end
27
+
28
+ Given /^an object containing multiple categories to export$/ do
29
+ @topic = Khayyam::Topic.new "vi"
30
+ @topic.regarding "movement" do |items|
31
+ items["h"] = "left"
32
+ items["j"] = "up"
33
+ end
34
+ @topic.regarding "commands" do |items|
35
+ items[":q"] = "quit"
36
+ items[":x"] = "save and quit"
37
+ end
38
+ end
39
+
40
+ Then /^it will contain all the data and categories in the original objects$/ do
41
+ @output.should eql(%{topic: vi\ncategories: \n movement: \n h: left\n j: up\n commands: \n \":q\": quit\n \":x\": save and quit\n})
42
+ end
43
+
44
+
45
+
46
+
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. .. spec spec_helper.rb])
2
+
3
+ Given /^a string containing data to import$/ do
4
+ @data = "topic: dairy\ncategories:\n cheese:\n cheddar: ubiquitous\n blue: crumbly"
5
+ end
6
+
7
+ When /^I tell khayaam to import the string$/ do
8
+ @topic = Khayyam::Topic.import @data
9
+ end
10
+
11
+ Then /^it will import the string into khayyam$/ do
12
+ @topic.class.should eql(Khayyam::Topic)
13
+ end
14
+
15
+ Then /^it will contain all the data in the string$/ do
16
+ @topic.name.should eql("dairy")
17
+ @topic.categories.should eql(["cheese"])
18
+ @topic.regarding("cheese") do |fact|
19
+ fact["cheddar"].should eql("ubiquitous")
20
+ fact["blue"].should eql("crumbly")
21
+ end
22
+ end
23
+
24
+
25
+
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'topic'
5
+
6
+ module Khayyam
7
+ VERSION = '0.0.1'
8
+ end
@@ -0,0 +1,53 @@
1
+ require 'yaml'
2
+
3
+ module Khayyam
4
+
5
+ #= Overview
6
+ # Khayyam::Topic: The class for interacting with topic pairs.
7
+ #
8
+ class Topic
9
+ attr_reader :name
10
+
11
+ def initialize name, facts={}
12
+ @name = name
13
+ @facts = facts
14
+ end
15
+
16
+ # returns an array of sub-topics
17
+ def categories
18
+ @facts.keys
19
+ end
20
+
21
+ # used to work with sub-topics
22
+ def regarding category
23
+ @facts[category] ||= {}
24
+ yield @facts[category]
25
+ end
26
+
27
+ # Export data to a string
28
+ # Example:
29
+ # topic = Khayyam::Topic.new "vi"
30
+ # topic.regarding "movement" do |items|
31
+ # items["h"] = "left"
32
+ # items["j"] = "up"
33
+ # end
34
+ # topic.regarding "commands" do |items|
35
+ # items[":q"] = "quit"
36
+ # items[":x"] = "save and quit"
37
+ # end
38
+ # output_string = topic.export
39
+ def export
40
+ output = YAML.dump_stream({'topic' => @name, 'categories' => @facts})
41
+ output[5..output.length]
42
+ end
43
+
44
+ # Import data from a string.
45
+ #
46
+ # Example:
47
+ # topic = Khayyam::Topic.import my_data
48
+ def self.import string
49
+ data = YAML.load "--- \n#{string}"
50
+ khayyam = Khayyam::Topic.new data["topic"], data["categories"]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'khayyam'
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
+
3
+ describe Khayyam::Topic do
4
+ it "should take the topic as a string on creation" do
5
+ topic = Khayyam::Topic.new "foo"
6
+ topic.name.should eql("foo")
7
+ end
8
+
9
+ it "should store topics and facts" do
10
+ topic = Khayyam::Topic.new "dairy"
11
+ topic.regarding "cheese" do |fact|
12
+ fact["cheddar"] = "ubiquitous"
13
+ end
14
+
15
+ topic.categories.should eql(["cheese"])
16
+ topic.regarding "cheese" do |fact|
17
+ fact["cheddar"].should eql("ubiquitous")
18
+ end
19
+ end
20
+
21
+ it "should export data to a YAML string" do
22
+ topic = Khayyam::Topic.new "dairy"
23
+ topic.regarding "cheese" do |fact|
24
+ fact["cheddar"] = "ubiquitous"
25
+ end
26
+
27
+ output = topic.export
28
+ output.should eql("topic: dairy\ncategories: \n cheese: \n cheddar: ubiquitous\n")
29
+ end
30
+
31
+ it "should import data from a YAML string" do
32
+ topic = Khayyam::Topic.import "topic: dairy\ncategories: \n cheese: \n cheddar: ubiquitous\n"
33
+ topic.name.should eql("dairy")
34
+ #topic.
35
+ end
36
+ end
37
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: khayyam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamal Hansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-22 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ description: A gem for easily moving data and definititions, such as vocabulary words and definitions to and from files
26
+ email:
27
+ - jamal.hansen@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - features/export.feature
42
+ - features/import.feature
43
+ - features/steps/export_steps.rb
44
+ - features/steps/import_steps.rb
45
+ - lib/khayyam.rb
46
+ - lib/topic.rb
47
+ - spec/spec.opts
48
+ - spec/spec_helper.rb
49
+ - spec/topic_spec.rb
50
+ has_rdoc: true
51
+ homepage: http://khayyam.rubyforge.org
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --main
55
+ - README.txt
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: khayyam
73
+ rubygems_version: 1.2.0
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: A gem for easily moving data and definititions, such as vocabulary words and definitions to and from files
77
+ test_files: []
78
+