Class: MarkdownLint::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/mdl/style.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all_rules) ⇒ Style

Returns a new instance of Style.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mdl/style.rb', line 7

def initialize(all_rules)
  @tagged_rules = {}
  @aliases = {}
  all_rules.each do |id, r|
    r.tags.each do |t|
      @tagged_rules[t] ||= Set.new
      @tagged_rules[t] << id
    end
    r.aliases.each do |a|
      @aliases[a] = id
    end
  end
  @all_rules = all_rules
  @rules = Set.new
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules


5
6
7
# File 'lib/mdl/style.rb', line 5

def rules
  @rules
end

Class Method Details

.load(style_file, rules) ⇒ Object


52
53
54
55
56
57
58
59
60
# File 'lib/mdl/style.rb', line 52

def self.load(style_file, rules)
  unless style_file.include?("/") or style_file.end_with?(".rb")
    style_file = File.expand_path("../styles/#{style_file}.rb", __FILE__)
  end
  style = new(rules)
  style.instance_eval(File.read(style_file), style_file)
  rules.select! {|r| style.rules.include?(r)}
  style
end

Instance Method Details

#allObject


23
24
25
# File 'lib/mdl/style.rb', line 23

def all
  @rules.merge(@all_rules.keys)
end

#exclude_rule(id) ⇒ Object


39
40
41
42
# File 'lib/mdl/style.rb', line 39

def exclude_rule(id)
  id = @aliases[id] if @aliases[id]
  @rules.delete(id)
end

#exclude_tag(t) ⇒ Object


48
49
50
# File 'lib/mdl/style.rb', line 48

def exclude_tag(t)
  @rules.subtract(@tagged_rules[t])
end

#rule(id, params = {}) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mdl/style.rb', line 27

def rule(id, params={})
  if block_given?
    raise "'rule' does not take a block. Should this definition go in a ruleset instead?"
  end
  id = @aliases[id] if @aliases[id]
  unless @all_rules[id]
    raise "No such rule: #{id}"
  end
  @rules << id
  @all_rules[id].params(params)
end

#tag(t) ⇒ Object


44
45
46
# File 'lib/mdl/style.rb', line 44

def tag(t)
  @rules.merge(@tagged_rules[t])
end