mummy 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a890241f44e9643fb33f575ad428c2e05f0cdd6a
4
- data.tar.gz: 367d61ed4e321e199abce4c61bbfa63b3d7dc02d
3
+ metadata.gz: db015bc733b6b49de96ef31c752283749544c3b5
4
+ data.tar.gz: 9d2001497f2fe74989004927d893797bf4583b94
5
5
  SHA512:
6
- metadata.gz: f55dd827b019bc2c1e60a61b646d42fe461f3994de62781a230a35e71da6ce78c9093984dbade9d72248d461845482318584264dda5f2196dfe392378e14916f
7
- data.tar.gz: 222ed2ce3fb044d68a438dfd5379850a77d8290aad5ecb806f59e624e9ff0807c45b26ef06e9776145a10317b7973600391f4fd5172ab174755292de8cdf69f0
6
+ metadata.gz: 1f91d1cf61000ad55269cea70d8df8fe09dbead2ee31c1a565ecd940892d4e04bb6968a8e68745b97d344f1c9c2ea22078f98899a6a17c7516526dda1b32da07
7
+ data.tar.gz: 14817da1a5a6aeaf290ae8a52da8a2dee6d1eedf9cbbf55b945fb0aa4dd6a4e57daa7de2f1c0e656b0eaf9fbb8f18be866e622600b9ad9d891c16fcf348b9b48
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.0
4
+ - 2.0.0
4
5
  before_install: gem install bundler -v 1.10.2
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Mummy
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/mummy.svg)](http://badge.fury.io/rb/mummy) [![Build Status](https://travis-ci.org/timrogers/mummy.svg)](https://travis-ci.org/timrogers/mummy)
4
+
3
5
  Mummy makes it easy to test yourself for tests and exams. *Just like your mum did back when you were younger.*
4
6
 
5
7
  ## Usage
6
8
 
7
- Install the gem:
9
+ Install the gem *(Ruby 2.0.0 and later only)*:
8
10
 
9
11
  ```bash
10
12
  $ gem install mummy
@@ -14,14 +16,14 @@ Then, run `mummy` with a path to a file to run your test from:
14
16
 
15
17
  ```bash
16
18
  $ mummy GV101/Democracy.txt
17
- $ mummy GV100/Plato.md
19
+ $ mummy GV100/Plato.md --markdown-heading-level 1
18
20
  ```
19
21
 
20
- You can write your tests in __Markdown__ (.md) and __plain-text__ (.txt) files.
22
+ You can write your tests in __Markdown__ (.md) and __plain-text__ (.txt) files. __Mummy__ will detect the right parser to use based on the file type, but you can specify this yourself with a `--parser` command line argument (e.g. `--parser markdown` or `--parser text`).
21
23
 
22
24
  If you're using a text file, just separate the terms you want to be tested on with line breaks.
23
25
 
24
- If you're using Markdown, prefix the terms to be tested on with `##` (i.e. write them as second-level headings).
26
+ If you're using Markdown, prefix the terms to be tested on with `##` (i.e. write them as second-level headings). You can change the heading level you want to look for from the default of H2 (`##`) by specifying a `--markdown-heading-level` command line option (e.g. `--markdown-heading-level 1` will look for lines starting with one "#").
25
27
 
26
28
  __Mummy__ will read the terms back to you in random order. Hit enter to move onto the next one, or enter an asterisk (`*`) before hitting enter if you want to run by that term again at the end.
27
29
 
@@ -35,7 +37,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
35
37
 
36
38
  Bug reports and pull requests are welcome on GitHub at https://github.com/timrogers/mummy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
37
39
 
38
-
39
40
  ## License
40
41
 
41
42
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/exe/mummy CHANGED
@@ -6,4 +6,5 @@ unless path = ARGV[0]
6
6
  raise "You must provide the path to a file as an argument to `mummy`."
7
7
  end
8
8
 
9
- Mummy::Test.from_file(path).run
9
+ options = Mummy::Options.parse
10
+ Mummy::Test.from_file(path, options).run
@@ -1,6 +1,9 @@
1
+ require "slop"
2
+
1
3
  require "mummy/version"
2
4
  require "mummy/test"
3
5
  require "mummy/parsers/base_parser"
4
6
  require "mummy/parsers/markdown_parser"
5
7
  require "mummy/parsers/txt_parser"
6
8
  require "mummy/constants"
9
+ require "mummy/options"
@@ -11,5 +11,17 @@ module Mummy
11
11
  TXT => Mummy::Parsers::TxtParser
12
12
  }.freeze
13
13
  end
14
+
15
+ module Parsers
16
+ PERMITTED = [Mummy::Parsers::MarkdownParser, Mummy::Parsers::TxtParser].freeze
17
+
18
+ MARKDOWN = "markdown".freeze
19
+ TEXT = "text".freeze
20
+
21
+ NAMES = {
22
+ MARKDOWN => Mummy::Parsers::MarkdownParser,
23
+ TEXT => Mummy::Parsers::TxtParser
24
+ }.freeze
25
+ end
14
26
  end
15
27
  end
@@ -0,0 +1,33 @@
1
+ require "slop"
2
+ require "mummy/constants"
3
+
4
+ module Mummy
5
+ class Options
6
+ def self.options
7
+ @options ||= Slop::Options.new.tap do |options|
8
+ options.string "-p", "--parser",
9
+ "Parser to use instead of detecting automatically" \
10
+ "(#{Constants::Parsers::NAMES.keys.join(', ')})"
11
+
12
+ options.on "-h", "--help" do
13
+ puts self
14
+ exit
15
+ end
16
+
17
+ Constants::Parsers::PERMITTED.each do |klass|
18
+ klass.provide_options(options)
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.parse(input = ARGV)
24
+ parser.parse(input).to_hash
25
+ end
26
+
27
+ private
28
+
29
+ def self.parser
30
+ @parser ||= Slop::Parser.new(options)
31
+ end
32
+ end
33
+ end
@@ -1,17 +1,24 @@
1
1
  module Mummy
2
2
  module Parsers
3
3
  class BaseParser
4
- def initialize(input)
4
+ def initialize(input, options = {})
5
5
  @input = input
6
+ @options = options
6
7
  end
7
8
 
8
9
  def items
9
10
  raise NotImplementedError, "#items must be imlemented by a BaseParser subclass"
10
11
  end
11
12
 
13
+ # Override this in a subclass if you want the parser to support command line options
14
+ # - see MarkdownParser for an example, or the `slop` readme
15
+ # (https://github.com/leejarvis/slop)
16
+ def self.provide_options(slop_options)
17
+ end
18
+
12
19
  private
13
20
 
14
- attr_reader :input
21
+ attr_reader :input, :options
15
22
  end
16
23
  end
17
24
  end
@@ -3,9 +3,23 @@ module Mummy
3
3
  class MarkdownParser < BaseParser
4
4
  def items
5
5
  @items ||= input.lines.select do |line|
6
- line[0..1] == "##"
6
+ line.start_with?("#{heading_marker} ")
7
7
  end.map { |line| line[2..-1].strip }
8
8
  end
9
+
10
+ def self.provide_options(slop_options)
11
+ slop_options.integer "--markdown-heading-level",
12
+ "Heading level to use to find items (e.g. 2 means '##')",
13
+ default: 2
14
+ end
15
+
16
+ private
17
+
18
+ # This weird symbol/string combo below is annoying. I've made a PR to `slop` to
19
+ # fix it, see https://github.com/leejarvis/slop/pull/169
20
+ def heading_marker
21
+ "#" * options[:"markdown-heading-level"]
22
+ end
9
23
  end
10
24
  end
11
25
  end
@@ -2,7 +2,7 @@ module Mummy
2
2
  module Parsers
3
3
  class TxtParser < BaseParser
4
4
  def items
5
- @items ||= input.lines.map(&:strip)
5
+ @items ||= input.lines.compact.map(&:strip)
6
6
  end
7
7
  end
8
8
  end
@@ -1,11 +1,17 @@
1
1
  module Mummy
2
2
  class Test
3
- def self.from_file(path)
3
+ def self.from_file(path, options = {})
4
4
  extension = File.extname(path)
5
5
  input = File.read(path)
6
6
 
7
- if parser = Mummy::Constants::Extensions::PARSERS[extension.downcase]
8
- items = parser.new(input).items
7
+ if options[:parser]
8
+ parser = Mummy::Constants::Parsers::NAMES[options[:parser].downcase]
9
+ raise "The specified parser, #{options[:parser]}, does not exist" unless parser
10
+
11
+ items = parser.new(input, options).items
12
+ new(items)
13
+ elsif parser = Mummy::Constants::Extensions::PARSERS[extension.downcase]
14
+ items = parser.new(input, options).items
9
15
  new(items)
10
16
  else
11
17
  raise "The file isn't of a supported extension - the following are supported: " \
@@ -19,6 +25,8 @@ module Mummy
19
25
  end
20
26
 
21
27
  def run
28
+ raise "No items were found - is your file formatted correctly?" unless items.any?
29
+
22
30
  items.shuffle.each_with_index do |item, index|
23
31
  puts "#{index + 1}/#{items.count}. #{item}"
24
32
  @starred.push(item) if $stdin.gets.chomp.include?("*")
@@ -1,3 +1,3 @@
1
1
  module Mummy
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.10"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
+
25
+ spec.add_runtime_dependency "slop", "~> 4.1.0"
24
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mummy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.1.0
55
69
  description:
56
70
  email:
57
71
  - tim@gocardless.com
@@ -73,6 +87,7 @@ files:
73
87
  - exe/mummy
74
88
  - lib/mummy.rb
75
89
  - lib/mummy/constants.rb
90
+ - lib/mummy/options.rb
76
91
  - lib/mummy/parsers/base_parser.rb
77
92
  - lib/mummy/parsers/markdown_parser.rb
78
93
  - lib/mummy/parsers/txt_parser.rb