Browse Source

Progress on a machine tag library for Ruby.

Douglas Thrift 10 years ago
commit
d01b10b921
14 changed files with 179 additions and 0 deletions
  1. 17 0
      .gitignore
  2. 2 0
      .rspec
  3. 3 0
      .travis.yml
  4. 4 0
      Gemfile
  5. 22 0
      LICENSE.txt
  6. 29 0
      README.md
  7. 8 0
      Rakefile
  8. 3 0
      lib/machine_tag.rb
  9. 0 0
      lib/machine_tag/set.rb
  10. 50 0
      lib/machine_tag/tag.rb
  11. 3 0
      lib/machine_tag/version.rb
  12. 25 0
      machine_tag.gemspec
  13. 11 0
      spec/machine_tag_spec.rb
  14. 2 0
      spec/spec_helper.rb

+ 17 - 0
.gitignore

@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp

+ 2 - 0
.rspec

@@ -0,0 +1,2 @@
+--format documentation
+--color

+ 3 - 0
.travis.yml

@@ -0,0 +1,3 @@
+language: ruby
+rvm:
+  - 1.9.3

+ 4 - 0
Gemfile

@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in machine_tag.gemspec
+gemspec

+ 22 - 0
LICENSE.txt

@@ -0,0 +1,22 @@
+Copyright (c) 2013 Douglas Thrift
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 29 - 0
README.md

@@ -0,0 +1,29 @@
+# MachineTag
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+    gem 'machine_tag'
+
+And then execute:
+
+    $ bundle
+
+Or install it yourself as:
+
+    $ gem install machine_tag
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request

+ 8 - 0
Rakefile

@@ -0,0 +1,8 @@
+require "bundler/gem_tasks"
+require "rspec/core/rake_task"
+require "yard"
+
+RSpec::Core::RakeTask.new(:spec)
+YARD::Rake::YardocTask.new
+
+task :default => :spec

+ 3 - 0
lib/machine_tag.rb

@@ -0,0 +1,3 @@
+require "machine_tag/version"
+require "machine_tag/tag"
+require "machine_tag/set"

+ 0 - 0
lib/machine_tag/set.rb


+ 50 - 0
lib/machine_tag/tag.rb

@@ -0,0 +1,50 @@
+module MachineTag
+  # A tag which can be a machine tag.
+  #
+  class Tag < String
+    # The regular expression for matching a machine tag
+    #
+    # @return [Regexp] the regular expression for matching a machine tag
+    MACHINE_TAG = /^(?<namespace>[a-zA-Z][a-zA-Z0-9_]*):(?<predicate>[a-zA-Z][a-zA-Z0-9_]*)=(?<value>.*)$/
+
+    # The namespace portion of the machine tag, +nil+ if the tag is not a machine tag
+    #
+    # @return [String, nil] the namespace portion of the machine tag, +nil+ if the tag is not a machine tag
+    #
+    attr_reader :namespace
+
+    # The predicate portion of the machine tag, +nil+ if the tag is not a machine tag
+    #
+    # @return [String, nil] the predicate portion of the machine tag, +nil+ if the tag is not a machine tag
+    #
+    attr_reader :predicate
+
+    # The value portion of the machine tag, +nil+ if the tag is not a machine tag
+    #
+    # @return [String, nil] the value portion of the machine tag is not a machine tag
+    #
+    attr_reader :value
+
+    # Creates a tag object which can be a machine tag.
+    #
+    # @param str [String] the tag string
+    #
+    def initialize(str)
+      super
+      if match = self.match(MACHINE_TAG)
+        @namespace = match[:namespace]
+        @predicate = match[:predicate]
+        @value = match[:value]
+        @value = $1 if @value =~ /^"(.*)"$/
+      end
+    end
+
+    # Returns whether this tag is a machine tag or not.
+    #
+    # @return [Boolean] +true+ if this tag is a machine tag, otherwise +false+
+    #
+    def machine_tag?
+      !!namespace
+    end
+  end
+end

+ 3 - 0
lib/machine_tag/version.rb

@@ -0,0 +1,3 @@
+module MachineTag
+  VERSION = "0.0.1"
+end

+ 25 - 0
machine_tag.gemspec

@@ -0,0 +1,25 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'machine_tag/version'
+
+Gem::Specification.new do |spec|
+  spec.name          = "machine_tag"
+  spec.version       = MachineTag::VERSION
+  spec.authors       = ["Douglas Thrift"]
+  spec.email         = ["douglas@douglasthrift.net"]
+  spec.description   = %q{A Ruby library for using Machine Tags}
+  spec.summary       = %q{Library for using Machine Tags}
+  spec.homepage      = "https://github.com/douglaswth/machine_tag"
+  spec.license       = "MIT"
+
+  spec.files         = `git ls-files`.split($/)
+  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
+  spec.require_paths = ["lib"]
+
+  spec.add_development_dependency "bundler", "~> 1.3"
+  spec.add_development_dependency "rake"
+  spec.add_development_dependency "rspec"
+  spec.add_development_dependency "yard", "~> 0.8.7.2"
+end

+ 11 - 0
spec/machine_tag_spec.rb

@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe MachineTag do
+  it 'should have a version number' do
+    MachineTag::VERSION.should_not be_nil
+  end
+
+  it 'should do something useful' do
+    false.should be_true
+  end
+end

+ 2 - 0
spec/spec_helper.rb

@@ -0,0 +1,2 @@
+$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+require 'machine_tag'