Class: Bio::Ucsc::Schema::Joiner

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-ucsc/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Joiner

Returns a new instance of Joiner.



23
24
25
26
27
# File 'lib/bio-ucsc/schema.rb', line 23

def initialize(text)
  @joiner = text << "\n" << EOF
  @variables = nil
  @identifiers = nil
end

Instance Attribute Details

#joinerObject (readonly)

Returns the value of attribute joiner.



21
22
23
# File 'lib/bio-ucsc/schema.rb', line 21

def joiner
  @joiner
end

Class Method Details

.load(uri = nil) ⇒ Object



29
30
31
32
# File 'lib/bio-ucsc/schema.rb', line 29

def self.load(uri=nil)
  uri ||= ALL_JOINER_URI
  new(URI(uri).read)
end

Instance Method Details

#define_association(klass) ⇒ Object



109
110
111
112
# File 'lib/bio-ucsc/schema.rb', line 109

def define_association(klass)
  krhash = find_association(class_to_table(klass))
  define_association_by_pkey_referer(krhash)
end

#identifiersObject



52
53
54
55
56
57
58
59
# File 'lib/bio-ucsc/schema.rb', line 52

def identifiers
  if @identifiers
    return @identifiers
  else
    parse
    return @identifiers
  end
end

#parseObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bio-ucsc/schema.rb', line 61

def parse
  enum = @joiner.lines.reject{|x|remove_indent(x).start_with?('#')}.each
  here = remove_indent(enum.next)
  loop do
    cmd, name, value = here.split(" ",3)
    case cmd
    when "set"
      @variables ||= Variables.new
      @variables[name] = value.split(",")
    when "identifier"
      @identifiers ||= Hash.new
      @identifiers[name] ||= Identifier.new
      if value
        value.split(" ").each do |attrib|
          type, info = attrib.split("=")
          @identifiers[name].attributes[type] = info
        end
      end
      @identifiers[name].comment = remove_indent(enum.next).gsub(/\"/, "")
      @identifiers[name].primary_key = remove_indent(enum.next)
      @identifiers[name].fields = Array.new
      here = remove_indent(enum.next)
      loop do
        @identifiers[name].fields << here
        peek = remove_indent(enum.peek)
        break if (peek.empty? || peek == EOF)
        here = remove_indent(enum.next)
      end
    when "type", "tablesIgnored"
      loop do
        peek = enum.peek
        break if (peek.empty? || peek == EOF)
        enum.next
      end
    when nil
      # ignore
    when "dependency", "databasesChecked", "databasesIgnored", "exclusiveSet"
      # ignore
    else
      raise "this should not happen."
    end
    peek = remove_indent(enum.peek)
    break if peek == EOF
    here = remove_indent(enum.next)
  end
  self
end

#variablesObject



34
35
36
37
38
39
40
41
# File 'lib/bio-ucsc/schema.rb', line 34

def variables
  if @variables
    return @variables
  else
    parse
    return @variables
  end
end

#variables=(val) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/bio-ucsc/schema.rb', line 43

def variables=(val)
  if @variables
    @variables = val
  else
    parse
    @variables = val
  end
end