Class: FieldMatter::StrangeMatter

Inherits:
Object
  • Object
show all
Defined in:
lib/fieldmatter/strangematter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_path) ⇒ StrangeMatter

Returns a new instance of StrangeMatter.



9
10
11
12
# File 'lib/fieldmatter/strangematter.rb', line 9

def initialize ( repo_path )
  @repo_path = repo_path
  @tags_matter = Hash.new
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/fieldmatter/strangematter.rb', line 7

def repo
  @repo
end

#repo_pathObject (readonly)

Returns the value of attribute repo_path.



7
8
9
# File 'lib/fieldmatter/strangematter.rb', line 7

def repo_path
  @repo_path
end

#tags_matterObject (readonly)

Returns the value of attribute tags_matter.



7
8
9
# File 'lib/fieldmatter/strangematter.rb', line 7

def tags_matter
  @tags_matter
end

Instance Method Details

#as_json(object) ⇒ Object



14
15
16
# File 'lib/fieldmatter/strangematter.rb', line 14

def as_json ( object )
  JSON.generate(object)
end

#mdluvin(file) ⇒ Object



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

def mdluvin ( file )
  file_path = self.repo_path + '/' + file
  tags = %x{mdls -name 'kMDItemOMUserTags' -raw "#{file_path}"|awk '/[^()]/ {print $NF}'|tr -d '\n'}.split(',')
  puts "Updating tags associated with #{file}: #{tags}"
  # Possibly temporary, might change the array/hash construction to different methods
  @tags_matter.store(file, tags)
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fieldmatter/strangematter.rb', line 18

def update
  changes = self.repo.status.changed        # Determine files/objects in the git repo that have been flagged for update
  
  changes.delete(".gitignore")              # Any non-tagged/tag-important files that aren't ignored in .gitignore or info/exclude 
  changes.delete("fieldmatter.json")        # are potential problems/waste of database space. This will delete them if they turn up.
  
  changes.keys.each do |file|               # for each file that has changed
    self.mdluvin( file )                    # show these files some mdluvin; aka get a list of extended attribute openmeta tags from mdls.
  end
  
  self.write_to_json                                        
end

#what_mattersObject



43
44
45
46
47
48
49
50
51
# File 'lib/fieldmatter/strangematter.rb', line 43

def what_matters
  what_matters = Hash.new
  @tags_matter.each do | filename, tags |
    strange_matter = Hash['kMDItemOMUserTags' => tags]
    what_matters.store(filename, strange_matter)
  end

return what_matters
end

#write_to_jsonObject



53
54
55
56
57
58
# File 'lib/fieldmatter/strangematter.rb', line 53

def write_to_json
  json_matters = self.as_json( self.what_matters )
  File.open("#{self.repo_path}/fieldmatter.json", "w") do |f|
    f.write(json_matters)
  end
end