Class: Ronn::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/ronn/index.rb

Overview

An individual index reference. A reference can point to one of a few types of locations:

- URLs: "http://man.cx/crontab(5)"
- Relative paths to ronn manuals: "crontab.5.ronn"

The #url method should be used to obtain the href value for HTML.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, name, location) ⇒ Reference

Returns a new instance of Reference.



149
150
151
152
153
# File 'lib/ronn/index.rb', line 149

def initialize(index, name, location)
  @index = index
  @name = name
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



147
148
149
# File 'lib/ronn/index.rb', line 147

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



146
147
148
# File 'lib/ronn/index.rb', line 146

def name
  @name
end

Instance Method Details

#manual?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/ronn/index.rb', line 155

def manual?
  name =~ /\([0-9]\w*\)$/
end

#pathObject



179
180
181
# File 'lib/ronn/index.rb', line 179

def path
  File.expand_path(location, File.dirname(@index.path)) if relative?
end

#relative?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/ronn/index.rb', line 167

def relative?
  !remote?
end

#remote?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/ronn/index.rb', line 163

def remote?
  location =~ /^(?:https?|mailto):/
end

#ronn?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/ronn/index.rb', line 159

def ronn?
  location =~ /\.ronn?$/
end

#urlObject



171
172
173
174
175
176
177
# File 'lib/ronn/index.rb', line 171

def url
  if remote?
    location
  else
    location.chomp('.ronn') + '.html'
  end
end