Module: SemanticHacker

Defined in:
lib/semantic_hacker.rb,
lib/semantic_hacker/api.rb,
lib/semantic_hacker/setup.rb,
lib/semantic_hacker/concept.rb,
lib/semantic_hacker/category.rb,
lib/semantic_hacker/signature.rb

Defined Under Namespace

Modules: Setup Classes: Api, Category, Concept, Signature

Constant Summary collapse

LIBPATH =

:stopdoc:

::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#api_key ⇒ Object

Returns the value of attribute api_key.



15
16
17
# File 'lib/semantic_hacker.rb', line 15

def api_key
  @api_key
end

#data_path ⇒ Object

Returns the value of attribute data_path.



15
16
17
# File 'lib/semantic_hacker.rb', line 15

def data_path
  @data_path
end

Class Method Details

.api_key(key = nil) ⇒ Object

:startdoc:



26
27
28
29
30
31
32
# File 'lib/semantic_hacker.rb', line 26

def self.api_key(key=nil)
  if key == nil
    @api_key
  else
    @api_key = key
  end
end

.categories ⇒ Object



58
59
60
# File 'lib/semantic_hacker.rb', line 58

def self.categories
  @categories
end

.check ⇒ Object



49
50
51
52
# File 'lib/semantic_hacker.rb', line 49

def self.check
  @categories = Setup.categories
  @labels = Setup.labels
end

.configured? ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/semantic_hacker.rb', line 109

def self.configured?
  api_key && data_path
end

.data_path(path = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/semantic_hacker.rb', line 34

def self.data_path(path=nil)
  if path == nil
    @data_path
  else
    @data_path = path
    SemanticHacker.check()
  end
end

.labels ⇒ Object



54
55
56
# File 'lib/semantic_hacker.rb', line 54

def self.labels
  @labels
end

.libpath(*args, &block) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/semantic_hacker.rb', line 66

def self.libpath( *args, &block )
  rv =  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
  if block
    begin
      $LOAD_PATH.unshift LIBPATH
      rv = block.call
    ensure
      $LOAD_PATH.shift
    end
  end
  return rv
end

.path(*args, &block) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/semantic_hacker.rb', line 83

def self.path( *args, &block )
  rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
  if block
    begin
      $LOAD_PATH.unshift PATH
      rv = block.call
    ensure
      $LOAD_PATH.shift
    end
  end
  return rv
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



101
102
103
104
105
106
107
# File 'lib/semantic_hacker.rb', line 101

def self.require_all_libs_relative_to( fname, dir = nil )
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '**', '*.rb'))

  Dir.glob(search_me).sort.each {|rb| require rb}
end

.version ⇒ Object

Returns the version string for the library.



45
46
47
# File 'lib/semantic_hacker.rb', line 45

def self.version
  @version ||= File.read(path('version.txt')).strip
end